Call AddIn-Functions from VBA-Macro

S

Steffen Grellmann

Hi newsgroup,

is it possible to call public functions of a COM-AddIn (made with VSTO
2005) from outside, especially from a VBA-macro?

Any help would be appreciated.

Kind regards,

Steffen
 
K

Ken Slovak - [MVP - Outlook]

Yes, it's possible. For an example download one of the VSTO templates I have
up for Outlook 2007 and look at how I handle setting up calls from the
outside to functions in the COM addin. The same would apply for other
versions of Outlook as well with VSTO.
 
S

Steffen Grellmann

Hi Ken,

thank you very much for replying.
Yes, it's possible. For an example download one of the VSTO templates I have
up for Outlook 2007 and look at how I handle setting up calls from the
outside to functions in the COM addin. The same would apply for other
versions of Outlook as well with VSTO.

But how do I call the CalledFromOutside() from my VBA-Project (which
is a global template in Word with a reference to the Outlook object
library)?

Kind regards,

Steffen
 
K

Ken Slovak - [MVP - Outlook]

In the VBA code you'd do something like this, assuming your addin ProgID was
"myAddin":

Dim oAddin As Office.ComAddin
' oOL is an Outlook.Application object

Set oAddin = oOL.COMAddins.Item("myAddin")
If Not (oAddin Is Nothing) Then
If oAddin.Connect = True Then 'if addin running
Dim addinObject As Object
Set addinObject = oAddin.Object
If Not (addinObject Is Nothing) Then
addinObject.CalledFromOutside() ' this is the call
End If
End If
End If
 
S

Steffen Grellmann

Hi Ken,

thank you very much for replying.
Dim oAddin As Office.ComAddin
' oOL is an Outlook.Application object

Set oAddin = oOL.COMAddins.Item("myAddin")
If Not (oAddin Is Nothing) Then
If oAddin.Connect = True Then 'if addin running
Dim addinObject As Object
Set addinObject = oAddin.Object
If Not (addinObject Is Nothing) Then
addinObject.CalledFromOutside() ' this is the call
End If
End If
End If

The oOL.COMAddins.Item supplies me the AddIns stored in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\Outlook\Addins

and not my VSTO 2007 SE AddIn stored in

HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins

How do I access the VSTO AddIn this way?

Kind regards,

Steffen
 
K

Ken Slovak - [MVP - Outlook]

That makes no sense at all. It shouldn't matter one way or the other where a
COM addin is registered, in either HKCU or HKLM.

If you look in the registry for your VSTO addin are you matching the
registration name exactly in your code?
 
S

Steffen Grellmann

Sorry, the registry confusion has been my fault. I first had an
underline in the registration name of my AddIn like "Test_2003".
Without that underline oAddin is initiated correctly and the item
collection is returning my AddIn as well as the other ones.

Nevertheless oAddin.Connect is still returning False for me.

Although you commented "'oOL is an Outlook.Application object" I had
to put in the following lines in order to prevent a compilation error
in Words VBA editor:

Dim oOL As Object
Set oOL = outlook.Application

Has this to do with my issue? Developing environment is VSTO SE 2005
and Word 2003/VBA with a reference set to the Outlook object model.
 
K

Ken Slovak - [MVP - Outlook]

If Outlook is started "headless" some versions of VSTO won't initialize the
addin. They only initialize the addin when Outlook is started with some UI
such as an Explorer or Inspector. That may have something to do with your
problem.

Another possibility is that since VSTO 2005 SE doesn't fire its Startup()
event until OnStartupComplete() fires in the extensibility interfaces that
you are checking for Connect too early.

I didn't bother writing complete code, just a snippet and indicated that you
need an Outlook.Application object which I called oOL in my code snippet. So
I would expect errors in Word VBA code unless you did instantiate an
Outlook.Application object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top