PC Review


Reply
Thread Tools Rate Thread

Communication between two Excel COM add-ins

 
 
Alex
Guest
Posts: n/a
 
      3rd Jan 2009
Hello all,

I need to communicate an Excel COM Add-in and a RTD automation server
that run at the same time when I open Excel. I need the RTD server to
get a reference to the COM add-in.

To do that I do the following:

In the COM Addin:
class MyCOMAddin : Extensibility.IDTExtensibility2
{

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
((COMAddIn)addInInst).Object = this;
}

}


In the RTD:
public int ServerStart(Excel.IRTDUpdateEvent CallbackObject)
{
Excel._Application app = (Excel._Application)
Marshal.GetActiveObject("Excel.Application");

MyCOMAddin addin = (MyCOMAddin) applicationObject.COMAddIns.Item
(ref progName).Object; // progName is "MyCOMAddin.Connect"

}


This approach works but has two problems:

1) Marshal.GetActiveObject("Excel.Application") may fail. So I may
have to retry this operation and try to force that object to be
registered. To do that I have to minimize and maximize the Excel
window when the addin is loaded.

2) If I open a second Excel application (not another workbook, a new
Excel instance). All this will fail. In particular, a new call to
applicationObject.COMAddIns.Item(ref progName).Object will return a
System.__ComObject that is not possible to cast to MyCOMAddin.

I couldn't find anything to solve that, do you have any solution for
these 2 issues?

Thanks!


 
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
Automation and communication between Access and Excel Peter Danes Microsoft Excel Discussion 19 22nd Feb 2007 03:58 PM
Access/Excel Communication andysgirl8800 Microsoft Excel Programming 1 26th May 2006 06:36 PM
communication between Excel files cpliu Microsoft Excel Programming 1 3rd May 2006 06:53 PM
Excel Communication Excel_Dumb Microsoft Excel Programming 3 27th May 2005 10:05 AM
Serial communication and export to excel =?Utf-8?B?Um9iIExvb2lqbWFucw==?= Microsoft C# .NET 1 12th Mar 2004 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 PM.