Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Referencing a com addin from a .net application via ole automation

Hi

I'm developing a c# application integrated with excel via ole automation.
I've developed an excel commandbar and handle buttons' click events. So far,
so good.

I got stuck with accessing my com addin from the .net application. I
couldn't find any official documentation, so following a vb example that I
found on the web, I'm passing the addin instance:

class Connect : Object, Excensibility.IDTExcensibility2
{
....
public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
addInInst.GetType().InvokeMember("Object",
BindingFlags.Public | BindingFlags.SetProperty, null, addInInst, new
object [] {this});
}
....
}

According to the example I should be able to the addin from my application:

foreach(Office.ComAddIn comAddin in xlApp.COMAddIns)
{
if (comAddIn.ProgId.Equals("ComAddin.Connect"))
{
ComAddin.Connect com = (ComAddin.Connect)
comAddIn.GetType().InvokeMember("Object", BindingFlags.Public |
BindingFlags.GetProperty, null, comAddIn, null);
}
}

However I get an exception saying that the 'Specified cast is not valid'.
Is there some other way to access my com addin?

Cheers,
Luke
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 233
Default Referencing a com addin from a .net application via ole automation

Luke,

you have a .NET c# app that launces/connects to Excel through (OLE)
Automation, and now want to launch a comm addin as well through the
..NET app?

The Excel.Applicatiob object has COmmaddins collection:

VB example:

Dim MyXLApp as Excel.Application
'.... connect to XL instance

'activates Registered COM addin:

MyXLApp.Commaddins("MyComProgID").Connect = True

Dm unseen

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Referencing a com addin from a .net application via ole automa

Hi

"DM Unseen" wrote:
you have a .NET c# app that launces/connects to Excel through (OLE)
Automation, and now want to launch a comm addin as well through the
..NET app?


No, my addin is loaded when excel starts. What I'm trying to do is to cast a
COMAddIn object retrieved from Excel.Application.COMAddIns collection to my
add-in type for further use.

As an example, here's the code from my .net app:

object myComAddIn = comAddIn.GetType().InvokeMember("Object",
BindingFlags.Public | BindingFlags.GetProperty,
null, comAddIn, null);

myComAddIn.GetType().InvokeMember("Test",
BindingFlags.Public | BindingFlags.InvokeMethod,
null, myComAddIn, null);

The above code successfully invokes the Test() method of my COM AddIn. What
I'm trying to do next is to cast myComAddIn to my com add-in type, which
fails.

The reason is to be able to subscribe to add-in's custom events. Any ideas?

Luke

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 233
Default Referencing a com addin from a .net application via ole automa

Got it,

No, i'm not sure if that is possible. I'f i might hazzard a guess:

You first need to register the typelib of the COM addin and and then
create an interop assembly for .NET and reference this in your .NET
project. Else your project does not know which events are sourced by
the COMM addin.

Then create a variable of your top level object with events (I do not
know the .NET equivalent) and assign the CoMaddin Object property to
it.

DM Unseen

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF's via Automation Addin in Excel 2010? Ralf Steinstraesser Excel Worksheet Functions 1 February 15th 10 03:44 PM
addIn functions in automation nicgendron Excel Programming 1 July 14th 05 10:35 AM
May be Automation AddIn loading problem!! Abhijit Excel Programming 0 June 6th 05 06:45 PM
Automation COM Addin with Excel Puneet Excel Programming 0 July 12th 04 07:50 PM
application is not getting closed through automation No Name Excel Programming 2 January 6th 04 04:24 AM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"