PC Review


Reply
Thread Tools Rate Thread

Call AddIn-Functions from VBA-Macro

 
 
Steffen Grellmann
Guest
Posts: n/a
 
      21st Jul 2008
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
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      21st Jul 2008
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.

--
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


"Steffen Grellmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Steffen Grellmann
Guest
Posts: n/a
 
      21st Jul 2008
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
 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      22nd Jul 2008
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

--
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


"Steffen Grellmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Steffen Grellmann
Guest
Posts: n/a
 
      23rd Jul 2008
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
 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Jul 2008
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?

--
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


"Steffen Grellmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Steffen Grellmann
Guest
Posts: n/a
 
      23rd Jul 2008
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.


On Wed, 23 Jul 2008 09:54:21 -0400, "Ken Slovak - [MVP - Outlook]"
<(E-Mail Removed)> wrote:

>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?
>
>--
>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
>
>
>"Steffen Grellmann" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Jul 2008
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.

--
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


"Steffen Grellmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Addin Macro Call Rick Microsoft Excel Programming 1 20th Dec 2007 06:19 AM
System.Addin , Call Host From Addin bivoauc Microsoft Dot NET Framework 2 5th Dec 2007 04:37 AM
Call an addin Macro from Workbook_Open event r.c.j.tongeren@arcadis.nl Microsoft Excel Programming 2 29th Aug 2007 07:19 PM
How map types when call functions defined in XLL AddIn from VBA Ravil Microsoft Excel Programming 1 23rd Mar 2006 10:49 PM
How to call COM Add-In functions from a macro Graham Microsoft Excel Programming 3 16th May 2004 10:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:56 PM.