I'm not sure if this problem is an Excel VBA problem or Visual Basic problem or a combination of the two. But I hope someone can help!
I'm trying to create code in Visual Basic Express (2010) that I can call from Excel VBA programs - VBA is too slow for the calculations. This is the first time I've used anything .NET related, so I'm starting with something really simple. And failing.
So far I haven't succeeded in creating a DLL that I can using in Excel VBA.
Following examples, what I have managed to do is:
1) Create a class in VB Express (2010), build it as a DLL and then use this class in another VB project. This worked smoothly - I just had to add a reference to the 2nd project which used the DLL. However, I'm unable to use this DLL in VBA.
2) I have also managed to create a DLL in VC++ Express (2010) and call this from Excel VBA. I never even had to add the DLL as a reference. I simply had a line of code in VBA
Declare Function timestwo Lib "D:\TestC++NET\TestCDLL\Debug\testCdll.dll" _
Alias "_timestwo@8" (ByVal x As Double) As Double
In this case, the DLL created in C++ contained just a single a function, not a class.
Problems
(1) When I try and add the DLL I created in (1) as a reference to VBA, I get an error in the VBA IDE which says "Can't add a reference to the specified file." (This seems a little odd because I had no problem adding the DLL as a reference to another VB 2010 project.)
(2) I do see references on the web to the fact that I may have to register the DLL. When I run Regsvr32 I get the error message "MyDLL.dll was loaded but the DLLServerRegister entry point was not found. This file can not be loaded."
(3) When looking at the Project Compile screen in Visual Basic Express 2010, I see fields like "Build Output Path" and various compile options. However, I do NOT see a "Register For COM Interop". (Which some info on the web seems to indicate I need to check) MS's documentation mentions that "Register For COM Interop" setting is not available for Windows Application or Console Application projects - but mine is a Class Library.
I also notice that both the Project "Application*" and "Compile*" tabs have an asterisk at the end of the name.
Does this perhaps mean that the options I'm looking for are not available in the VB 2010 Express version and that I can't create a DLL with VB 2010 Express? (But it seems strange that I could get a simple C++ function to be accessible in VBA via a DLL.)
Yours, increasingly baffled
Hedgepiglet
So....how do I go about creating a DLL that can actually be "seen" and used by VBA? I'd prefer not to have to register the DLL - but if I do have to, I can live with this.
Any help, hints, tips or tricks would be gratefully appreciated!
Bookmarks