Hi Snark,
There is an known issue in the Office XP PIA which will cause the problem
and the problem has been fixed in the Office 2003 PIA.
Now to workaround the problem, I think we can try to sink the problem
ourselves.
private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass exApp;
private void button1_Click(object sender, System.EventArgs e) //sink the
events
{
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)exApp;
// Get the GUID of the EApplication interface.
Guid guid=typeof(Excel.AppEvents).GUID;
// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid,out m_oConnectionPoint);
// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this,out m_Cookie);
}
private void button2_Click(object sender, System.EventArgs e)
{
m_oConnectionPoint.Unadvise(m_Cookie);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
GC.Collect();
}
[DispId(1560)]
public void SheetBeforeRightClick(object Sh , object Target ,ref bool
Cancel) //Event handler function
{
Cancel = true;
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Create an instance of Excel .
exApp = new Excel.ApplicationClass();
// Show Excel to the user.
exApp.Visible = true;
}
How To Handle PowerPoint Events With Visual C# .NET
http://support.microsoft.com/default...B;EN-US;308825
HOW TO: Establish a COM Event Sink with Return Values in the .NET Framework
by Using Visual Basic .NET (810228)
http://support.microsoft.com/default...B;EN-US;810228
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.