I'm wondering if VBA and VB.NET can be called by one another, and how
you would go about doing it? Does anyone know where I can get some
code examples?
They can, under certain circumstances. If you're automating the Office
application from a Windows Form app, for example, you can use
theApp.Run "Macro name" (the Application object's Run method).
If you have .NET code in a COM DLL, then you can add a reference to the
DLL (just as for any DLL), then call any public methods.
It's also possible use a "callback": a VBA sub, to which you pass an
object (instance of your .NET class) that the sub will assign to a
(global) variable of type Object. Through this object you can call any
public method in the class. The VBA part would look something like
this:
Dim myNETClassObject as Object
Public Sub LinkInNetClass(objNET as Object)
Set myNETClassObject = objNET
End Sub
Public Sub UseNetMethod
myNETClassObject.MethodName
End Sub
Your .NET app would call LinkInNetClass at some point (on Startup, for
example).
Andrew Whitechapel's book .NET Development for Microsoft Office does a
really good job of describing these possibilities, with sample code.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail