Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2007

Tip: Looking for answers? Try searching our database.

Using .NET COM object in VBA fails

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tstefany@gmx.de - 02 Jul 2007 09:09 GMT
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?
G Himangi - 03 Jul 2007 12:43 GMT
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.ssware.com
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
---------

>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
[quoted text clipped - 47 lines]
> methods in the VBA intellisense.
> Any ideas?
tstefany@gmx.de - 04 Jul 2007 13:34 GMT
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.

> 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
[quoted text clipped - 66 lines]
>
> - Zitierten Text anzeigen -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.