I have created a basic COM DLL with ATL on VS2012. It's called testCOM.dll and it only has one class called CSimpleObj. CSimpleObj has just one method called addValues which adds two values.
I've registered the DLL with Windows 7 64-bit. In VBA, I manually add a reference to the DLL and the below code works properly
Dim Obj As New testCOMLib.SimpleObj
MsgBox Obj.addValues(1,2)
And it give a message with number 3.
Now If I run the vbs which includes:
Dim Obj
Set Obj = CreateObject("testCOMLib.SimpleObj")
It constantly gives an error and is not able to create the object. But if I use the "Excel.Application"
ProgID (as an example) for the CreateObject method, it works fine.
I think there is an issue with registering the DLL. I've checked the registry, and the keys for the COM and the type library is already there.
What should I do?
Set myCOMobj = GetObject("C:\pathToMyCOM.dll")
thenmyCOMobj.addValues(1,2)
. Also make sure you are not actually using the MSgBox from VBScript – user2140173CreateObject("testCOMLib.SimpleObj")
? Does that work in Excel? – user2140173CreateObject
in VBA, it likely won't work there, either. – Bond