tstefany
7/2/2007 8:10:00 AM
I have a problem using .NET assemblies by their COM interface from
VBA. Everything works well on my machine, but on a different PC I
allways get the error message: "Automation error. The system cannot
find the file specified."
Creating the .NET component in VBA fails when it has been built with
VS 2005. When I build it with VS 2003 it works on my machine and also
on the other machine. Creating the component in a VB6 executable works
well in all combinations (VS2003 and VS2005 on both machines). I see
this problem only with VBA.
Both machines are running Office 2003, VBA: 6.4.9972
My machine has VS 2003 and VS 2005 installed, the other machine has VS
2003 and .NET 2.0 installed.
My VB.NET sample class:
Imports System.Runtime.InteropServices
<ComClass("1D4A6BFA-71B0-4841-AC0E-55514AD14DEA",
"FEDCBAB4-7BD5-4272-8E9B-91CB81ECC350")> _
Public Class SimpleTestClass
Public Sub New()
' we do nothing special here
End Sub
Public Sub Method1()
MsgBox("Method1 called")
End Sub
Public Sub Method2(ByVal val As Integer)
MsgBox("Method2 called, value: " + val.ToString())
End Sub
End Class
In the assembly information dialog I've checked "Make assembly COM-
Visible"
On the "Compile" tab I've also checked "Register for COM interop"
When I try to call this object form a VBA macro like this one:
Public Sub DoTheTest()
Dim oTest As SimpleTestClass
Set oTest = New SimpleTestClass
oTest.Method1
End Sub
I get the error message when executing the line "Set ... ".
The typelib seems to be well registered, because I can see the
SimpleTestClass on the reference tab and could also see all the
methods in the VBA intellisense.
Any ideas?