VSTO COM Add-In with UDF's


M

ma1achai

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

Advertisements

M

ma1achai

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
 
K

Ken Slovak - [MVP - Outlook]

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

ma1achai

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

Bernhard Marx

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

:

Previous Posts In This Thread:

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!

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

:

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 Slova
[MVP - Outlook
http://www.slovaktech.co
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.ht


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

:


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
 
J

jputman

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

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!

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

:

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 Slova
[MVP - Outlook
http://www.slovaktech.co
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.ht


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

:

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
 
R

Rashmi Anand

@ jputman

Thanks a MILLION...
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!
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
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.




news:45886E44-18F0-4E1E-A127-BB875A0177C5@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:
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...
 
Ad

Advertisements

B

Bernd Truckses

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




news:45886E44-18F0-4E1E-A127-BB875A0177C5@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:
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...
 

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