Hi all,
I am using VB Express 2008 and Excel 2007. I want to create a DLL in VB Express and call functions and procedures from the DLL in Excel VBA.
I have found many references on the web for how to do this, but I do not seem to have all the buttons in VB Express that is discussed on the forums. I end up getting an error message in VBA with the message: "Automation error - The system cannot find the file specified"
Here is what I did:
- Created a new project - getitright - in VB Express with the Class Library template
- I added a class called Class_getitright (I do not have the option to select the COM class template when I create a class)
- This is the code in the class (I did not go the GUID route as I do not have the option under Tools to create new GUIDS):
Public
Class Class_getitright
Public Sub New()
MyBase.New()
End Sub
<Runtime.InteropServices.ComVisible(
True)> _
Public Function Add_getitright(ByVal first As Integer, ByVal second As Integer) As Integer
Add_getitright = first + second
End Function
End
Class
4. I then went to project Properties > Application > Assembly Information and I ticked the box that says "Make assembly COM visible".
5. I do NOT have the option on the Compile tab that says “Register for COM interop”
6. I then selected Build getitright from the menu
7. Next in the command window I used the regasm utility to build the tlb file, which worked
8. In Excel I went to Tools > References and added the getitright.tlb file
9. In VBA, I put the following code:
Option Explicit
Sub test_dll()
Dim MF As New getitright.Class_getitright
Dim x As Integer
Dim y As Integer
Dim answer As Integer
x = 1
y = 2
answer = MF.Add_getitright(x, y)
Debug.Print (answer)
End Sub
But when I run it I get the error "Automation error - The system cannot find the file specified"
What am I doing wrong or how can I make the setting "Register for COM interop" visible in my Compile tab in VB Express 2008?
Not sure if this is a VB issue or a VBA issue, so please redirect me if Im in the wrong forum.
Thanks in advance!