Just after a little help with late binding.
I am trying to belate bind excel and I have no problems. Only when I have multiple excel instances where I run into some problems.
I would like to be able to determine which excel instance is bound to (and link events, etc.). The main reason is that I have an application that opens an Excel document from a third-party tool and events are not processed. I want to be able to use a specific excel instance that I know is open to catch events. The only problem is that excel is already open by the user (no matter how).
If excel opens after binding, obviously I have no problem. Only when excel is already open.
It seems that the binding is done with the first open, open.
Here is the actual code:
Type excelType = Type.GetTypeFromProgID("Excel.Application");
if (excelType == null)
throw new Exception(error);
excelApplication = Marshal.GetActiveObject("Excel.Application");
if (excelApplication == null)
throw new Exception(error);
this.withEvents = withEvents;
if (this.withEvents)
{
excelEvents = new ExcelApplicationEvents();
IConnectionPointContainer connectionPointContainer = excelApplication as IConnectionPointContainer;
Guid guid = new Guid("00024413-0000-0000-C000-000000000046");
connectionPointContainer.FindConnectionPoint(ref guid, out connectionPoint);
connectionPoint.Advise(excelEvents, out sinkCookie);
excelEvents.WorkbookBeforeSaveEvent += new EventHandler<WorkbookEventArgs>(ExcelEventsWorkbookBeforeSaveEvent);
}
Any ideas?
Greetings
Dale.
user188844
source
share