Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

VSTO COM Add-In with UDF's

113 views
Skip to first unread message

ma1achai

unread,
Jun 18, 2008, 7:35:00 PM6/18/08
to
There is a question down there... sorry for the long setup:

I have created a VSTO Com Add-in that has creates it's own ribbon in Excel
and provides a way for the user to login to my code through a Ribbon button.
For simplicity sake, Lets say I keep the username in a static Class LoginInfo.

Additionally, I want to expose some functions as UDF's that the user can use
directly within a cell. I have done so by marking a 'MyFunctions' class
AutoDual and made it ComVisible. This results in correctly creating an
Automation Add-In.

Everything appeared to work at first... user could login through the Ribbon
and could also use simple UDF's (Add two numbers, return a hard-coded string,
etc.). However, the problem I am seeing is when I try to get a UDF to return
information that was collected by the Com Add-In portion (like the username
from LoginInfo), it does not see this as having been set yet.

What it appears is that the COM Add-In and the Automation Add-In are
actually separate instances that cannot share code... is this correct? And
is there some way to get this to work?

It seems like there is simply something easy that I need to set to get this
correct...

thanks for any help!

ma1achai

unread,
Jun 19, 2008, 8:37:00 AM6/19/08
to
Jialiang, Ken, or anyone... please help! :)

I have created a simple solution that I can email someone to take a look at
this issue, if needed. I am really just looking for a way for ribbon
controls and UDF's to be able to access the same static C# code... seems like
it should just work! =p

Ken Slovak - [MVP - Outlook]

unread,
Jun 19, 2008, 9:03:58 AM6/19/08
to
I don't have an Excel solution like that but my Outlook 2007/VSTO 2005SE
template for C# does show an example of calling an internal method inside an
Outlook COM addin that can access anything inside the addin. You might want
to take a look at that for one method of doing what you want.

The templates are at http://www.slovaktech.com/outlook_2007_templates.htm.
See if that helps.

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


"ma1achai" <ma1a...@discussions.microsoft.com> wrote in message
news:45886E44-18F0-4E1E...@microsoft.com...

ma1achai

unread,
Jul 1, 2008, 10:50:02 AM7/1/08
to
Thank you for your help Ken!

I ended up finding a great method to do what I was trying to do... that is,
loading a COM Add-In and an Automation Add-In and having them share code.
What I needed to do was, during the Startup event of the COM Add-In, call the
Evaluate method of the Excel Application object with the name of any of the
functions from my Autoation Add-In. This loads them both into the same
AppDomain, which means that they can then share code. yay!

thanks again...

bernhardmarx

unread,
Dec 17, 2009, 3:25:23 AM12/17/09
to
Hi ma1acha,

may I ask you to share with us some code. I acutally have the thoughts but I'm stuck...

Thanks for your help!

Bernhard

ma1acha wrote:

Thank you for your help Ken!

01-Jul-08

Thank you for your help Ken!

I ended up finding a great method to do what I was trying to do... that is,
loading a COM Add-In and an Automation Add-In and having them share code.
What I needed to do was, during the Startup event of the COM Add-In, call the
Evaluate method of the Excel Application object with the name of any of the
functions from my Autoation Add-In. This loads them both into the same
AppDomain, which means that they can then share code. yay!

thanks again...

"Ken Slovak - [MVP - Outlook]" wrote:

Previous Posts In This Thread:

On Wednesday, June 18, 2008 7:35 PM
ma1acha wrote:

VSTO COM Add-In with UDF's


There is a question down there... sorry for the long setup:

I have created a VSTO Com Add-in that has creates it's own ribbon in Excel
and provides a way for the user to login to my code through a Ribbon button.
For simplicity sake, Lets say I keep the username in a static Class LoginInfo.

Additionally, I want to expose some functions as UDF's that the user can use
directly within a cell. I have done so by marking a 'MyFunctions' class
AutoDual and made it ComVisible. This results in correctly creating an
Automation Add-In.

Everything appeared to work at first... user could login through the Ribbon
and could also use simple UDF's (Add two numbers, return a hard-coded string,
etc.). However, the problem I am seeing is when I try to get a UDF to return
information that was collected by the Com Add-In portion (like the username
from LoginInfo), it does not see this as having been set yet.

What it appears is that the COM Add-In and the Automation Add-In are
actually separate instances that cannot share code... is this correct? And
is there some way to get this to work?

It seems like there is simply something easy that I need to set to get this
correct...

thanks for any help!

On Thursday, June 19, 2008 8:37 AM
ma1acha wrote:

Jialiang, Ken, or anyone... please help!
Jialiang, Ken, or anyone... please help! :)

I have created a simple solution that I can email someone to take a look at
this issue, if needed. I am really just looking for a way for ribbon
controls and UDF's to be able to access the same static C# code... seems like
it should just work! =p


"ma1achai" wrote:

On Thursday, June 19, 2008 9:03 AM


Ken Slovak - [MVP - Outlook] wrote:

I don't have an Excel solution like that but my Outlook 2007/VSTO 2005SE
I don't have an Excel solution like that but my Outlook 2007/VSTO 2005SE
template for C# does show an example of calling an internal method inside an
Outlook COM addin that can access anything inside the addin. You might want
to take a look at that for one method of doing what you want.

The templates are at http://www.slovaktech.com/outlook_2007_templates.htm.
See if that helps.

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


"ma1achai" <ma1a...@discussions.microsoft.com> wrote in message
news:45886E44-18F0-4E1E...@microsoft.com...

On Tuesday, July 01, 2008 10:50 AM
ma1acha wrote:

Thank you for your help Ken!
Thank you for your help Ken!

I ended up finding a great method to do what I was trying to do... that is,
loading a COM Add-In and an Automation Add-In and having them share code.
What I needed to do was, during the Startup event of the COM Add-In, call the
Evaluate method of the Excel Application object with the name of any of the
functions from my Autoation Add-In. This loads them both into the same
AppDomain, which means that they can then share code. yay!

thanks again...

"Ken Slovak - [MVP - Outlook]" wrote:


Submitted via EggHeadCafe - Software Developer Portal of Choice
.NET Framework - Internals of Delegate Chaining
http://www.eggheadcafe.com/tutorials/aspnet/6c87597e-9283-4c92-a8ba-22e0224936d0/net-framework--internal.aspx

jputman

unread,
Feb 10, 2010, 4:13:55 PM2/10/10
to
[Note: I am the user that previously had the alias ma1achai]

Sorry Berhard, there was a year and a half between posts... and I just came back to this post by chance. Here is a simple example, assuming that you have an Automation Add-In that has the ProgId set to "MyCompany.DataFunctions" and a function named "MyFunction":

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// The format for the call should be:
// "=[ProgId].[FunctionName]()"
// so it might look like the following:
this.Application.Evaluate("=MyCompany.DataFunctions.MyFunction()");

}

Hope that helps...

Bernhard Marx wrote:

Please post code
17-Dec-09

Hi ma1acha,

may I ask you to share with us some code. I acutally have the thoughts but I'm stuck...

Thanks for your help!

Bernhard

Previous Posts In This Thread:

thanks for any help!


"ma1achai" wrote:

thanks again...

On Thursday, December 17, 2009 3:25 AM
Bernhard Marx wrote:

Please post code
Hi ma1acha,

may I ask you to share with us some code. I acutally have the thoughts but I'm stuck...

Thanks for your help!

Bernhard


Submitted via EggHeadCafe - Software Developer Portal of Choice

Sending SMTP email from within BizTalk Orchestration
http://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1716445b26bc/sending-smtp-email-from-w.aspx

Rashmi Anand

unread,
Feb 23, 2011, 2:07:27 AM2/23/11
to
@ jputman

Thanks a MILLION...

>>> template for C# does show an example of calling an internal method inside an
>>> Outlook COM addin that can access anything inside the addin. You might want
>>> to take a look at that for one method of doing what you want.
>>>
>>> The templates are at http://www.slovaktech.com/outlook_2007_templates.htm.
>>> See if that helps.
>>>
>>> --
>>> 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
>>>
>>>
>>> "ma1achai" <ma1a...@discussions.microsoft.com> wrote in message
>>> news:45886E44-18F0-4E1E...@microsoft.com...


>>>> On Tuesday, July 01, 2008 10:50 AM ma1acha wrote:

>>>> Thank you for your help Ken!
>>>>

>>>> I ended up finding a great method to do what I was trying to do... that is,
>>>> loading a COM Add-In and an Automation Add-In and having them share code.
>>>> What I needed to do was, during the Startup event of the COM Add-In, call the
>>>> Evaluate method of the Excel Application object with the name of any of the
>>>> functions from my Autoation Add-In. This loads them both into the same
>>>> AppDomain, which means that they can then share code. yay!
>>>>
>>>> thanks again...
>>>>
>>>> "Ken Slovak - [MVP - Outlook]" wrote:


>>>>> On Thursday, December 17, 2009 3:25 AM Bernhard Marx wrote:

>>>>> Hi ma1acha,
>>>>>
>>>>>
>>>>>
>>>>> may I ask you to share with us some code. I acutally have the thoughts but I'm stuck...
>>>>>
>>>>>
>>>>>
>>>>> Thanks for your help!
>>>>>
>>>>>
>>>>>
>>>>> Bernhard


>>>>>> On Wednesday, February 10, 2010 4:13 PM jputman wrote:

>>>>>> [Note: I am the user that previously had the alias ma1achai]
>>>>>>
>>>>>>
>>>>>>
>>>>>> Sorry Berhard, there was a year and a half between posts... and I just came back to this post by chance. Here is a simple example, assuming that you have an Automation Add-In that has the ProgId set to "MyCompany.DataFunctions" and a function named "MyFunction":
>>>>>>
>>>>>>
>>>>>>
>>>>>> private void ThisAddIn_Startup(object sender, System.EventArgs e)
>>>>>>
>>>>>> {
>>>>>>
>>>>>> // The format for the call should be:
>>>>>>
>>>>>> // "=[ProgId].[FunctionName]()"
>>>>>>
>>>>>> // so it might look like the following:
>>>>>>
>>>>>> this.Application.Evaluate("=MyCompany.DataFunctions.MyFunction()");
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> Hope that helps...


>>>>>> Submitted via EggHeadCafe
>>>>>> .NET Windows Services - Timer, Debugging, and Installation
>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/0ddb1434-d3c9-424c-8b12-bdf75c50588c/net-windows-services--timer-debugging-and-installation.aspx

Bernd Truckses

unread,
Aug 11, 2011, 5:09:34 AM8/11/11
to
Hi jputman,

I hope that you still looking at this thread...

I've tried your suggestion (with Office2010), but somehow during the ThisAddIn_Startup() method, the
this.Application.Evaluate( "=MyMethod()" ) call goes wrong, return value is the err code for "ErrName".

I've tried all variations of the name (with ProgID, without ProgID, ...) but nothing helps.

When I do this call at the Application_WorkbookOpen() event when opening an empty workbook file, everything is OK - I don't even need the ProgID then, just the UDF name is enough...
In this case the UDF is called and the automation-Addin containing the UDF is loaded in the AppDomain of my regular AddIn.

Do you know what is going wrong there - maybe an Excel2010 Issue? is there a known workaround?


best regards,
Bernd

0 new messages