Excel OLEObect.GotFocus delegate handler failing

B

Bob Griswold

This code fires a an COMException. The problem is that the Connectionpoint
cannot be found. I know this because of the stack trace and I've broke the
function down and even used enumconnectionpoints and the connection point is
there.

When I enumconnectionpointes on the OLEObject I get a IUnkownreturned.
I would appreciate any help. This event is crucial to completing my projects

Type excelType = Type.GetTypeFromProgID("Excel.Application");
Excel._Application excelApplication = (Excel._Application)
Activator.CreateInstance(excelType);
excelApplication.Workbooks.Add(Type.Missing);
excelApplication.Visible = true;
Excel.Worksheet activeWorksheet = (Excel.Worksheet)
excelApplication.ActiveSheet;
Excel.OLEObjects objCollection = (Excel.OLEObjects)
activeWorksheet.OLEObjects(Type.Missing);
Excel.OLEObject objBarcode = objCollection.Add("Word.Document",
null,
null, null, null, null, null, 0,0,100,100);
try
{
objBarcode.GotFocus += new

Excel.OLEObjectEvents_GotFocusEventHandler(objBarcode_GotFocus);
}
catch( COMException e)
{
MessageBox.Show(e.ToString());
}

The message is

"System.Runtime.InteropServices.COMException (0x80040200): Exception from
HRESULT: 0x80040200\r\n at
System.Runtime.InteropServices.UCOMIConnectionPointContainer.FindConnectionPoint(Guid&
riid, UCOMIConnectionPoint& ppCP)\r\n at
Microsoft.Office.Interop.Excel.OLEObjectEvents_EventProvider.Init()\r\n at
Microsoft.Office.Interop.Excel.OLEObjectEvents_EventProvider.add_GotFocus(OLEObjectEvents_GotFocusEventHandler
)\r\n at
Microsoft.Office.Interop.Excel.OLEObjectEvents_Event.add_GotFocus(OLEObjectEvents_GotFocusEventHandler
)\r\n at ZetaLateBindingComEvents.Program.Main(String[] args) in
C:\\temp\\LateBinding\\Program.cs:line 57"
 

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

Similar Threads

OLEObject.GotFocus 0

Top