Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / July 2008

Tip: Looking for answers? Try searching our database.

Call AddIn-Functions from VBA-Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steffen Grellmann - 21 Jul 2008 11:29 GMT
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
Ken Slovak - [MVP - Outlook] - 21 Jul 2008 15:01 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm

> Hi newsgroup,
>
[quoted text clipped - 6 lines]
>
> Steffen
Steffen Grellmann - 21 Jul 2008 20:54 GMT
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
Ken Slovak - [MVP - Outlook] - 22 Jul 2008 14:23 GMT
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

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm

> Hi Ken,
>
[quoted text clipped - 13 lines]
>
> Steffen
Steffen Grellmann - 23 Jul 2008 13:43 GMT
Hi Ken,

thank you very much for replying.

>Dim oAddin As Office.ComAddin
>' oOL is an Outlook.Application object
[quoted text clipped - 9 lines]
>    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
Ken Slovak - [MVP - Outlook] - 23 Jul 2008 14:54 GMT
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?

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm

> Hi Ken,
>
[quoted text clipped - 27 lines]
>
> Steffen
Steffen Grellmann - 23 Jul 2008 21:06 GMT
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.

>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.
[quoted text clipped - 33 lines]
>>
>> Steffen
Ken Slovak - [MVP - Outlook] - 23 Jul 2008 21:34 GMT
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.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm

> Sorry, the registry confusion has been my fault. I first had an
> underline in the registration name of my AddIn like "Test_2003".
[quoted text clipped - 12 lines]
> 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.
 
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.