I have tried to create a very basic C# library and expose it through COM interface so that I can access it from VBA, but at runtime it throws an error "Class does not support Automation or does not support expected interface"
I have read all the online tutorials and done exactly as specified so am very confused why this is. My basic class is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace PDCCOMTest
{
[ComVisible(true)]
public interface IPDCCOMTest
{
string SubmitRequest(string requestXML);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IPDCCOMTest))]
[ProgId("PDCCOMTest.PDCCOMTest")]
public class PDCCOMTest : IPDCCOMTest
{
public string SubmitRequest(string requestXML)
{
return "hello world";
}
}
}
And in the project settings I have gone to Application -> Assembly Information -> Make assembly COM visible (Set to ON) and Build -> Register for COM interop (Set to ON)
I compile and build the solution, then load up Excel and set up a basic button macro sheet. In this, I go to References and under the list of COM objects, my new C# COM assembly appears and I check it. I am then able to discover the types with Intellisense and the SubmitRequest method is available from Intellisense so it is picking all that up fine. The VBA code is as follows
Private Sub CommandButton1_Click()
Dim oObj As New PDCCOMTest.PDCCOMTest
Dim text As String
test = oObj.SubmitRequest("test")
End Sub
When I then run the sheet and click the button, it throws the error on the last line of the Sub above, ie the SubmitRequest() line
"Error 430 : Class does not support Automation or does not support expected interface"
Can anyone please suggest what I have overlooked and why this is happening?
Thanks, James
text
andtest
in your vba code. – assylias May 21 '13 at 12:45