[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

Using .NET COM object in VBA fails

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?

2 Answers

G Himangi

7/3/2007 11:43:00 AM

0

I am guessing the problem is because of mismatched versions of the .Net
runtime. The VBA engine might have already loaded v1.1 of the runtime and so
it is unable to load your object created with .Net 2.0

---------
- G Himangi, Sky Software http://www....
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------




<tstefany@gmx.de> wrote in message
news:1183363773.458659.284620@k79g2000hse.googlegroups.com...
>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?
>


tstefany

7/4/2007 12:35:00 PM

0

Thank you, this solved the problem!
I need a "Exel.exe.config" file, where I have to specify to use
the .NET 2.0 runtime.


On 3 Jul., 13:43, "G Himangi" <i...@ssware.com> wrote:
> I am guessing the problem is because of mismatched versions of the .Net
> runtime. The VBA engine might have already loaded v1.1 of the runtime and so
> it is unable to load your object created with .Net 2.0
>
> ---------
> - G Himangi, Sky Software http://www....
> Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
> Browsing Functionality For Your App (.Net & ActiveX Editions).
> EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
> EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
> rapidly in .Net
> ---------
>
> <tstef...@gmx.de> wrote in message
>
> news:1183363773.458659.284620@k79g2000hse.googlegroups.com...
>
>
>
> >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?- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -