Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Why are some events of the Office Object Model not available from C# in the source code editor?
Ask a questionAsk a question
 

LockedWhy are some events of the Office Object Model not available from C# in the source code editor?

Locked

  • Sunday, February 08, 2009 12:22 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Why are some events of the Office Object Model not available from C# in the source code editor?

     
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Answers

  • Sunday, February 08, 2009 12:23 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This usually happens when the Office Object has a method and an event with the same name. By default, when we type the uniform name, Visual Studio will take it as a method instead of the event.

    To use the event correctly, we need to firstly cast the object to the XXXEvents_Event type and then register the corresponding event. The following code shows an example for the Activate event of the Excel Workbook:

    ((Excel.WorkbookEvents_Event)(Globals.ThisWorkbook.InnerObject)).Activate +=

        new Excel.WorkbookEvents_ActivateEventHandler(ThisWorkbook_Activate);




    For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

All Replies

  • Sunday, February 08, 2009 12:23 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This usually happens when the Office Object has a method and an event with the same name. By default, when we type the uniform name, Visual Studio will take it as a method instead of the event.

    To use the event correctly, we need to firstly cast the object to the XXXEvents_Event type and then register the corresponding event. The following code shows an example for the Activate event of the Excel Workbook:

    ((Excel.WorkbookEvents_Event)(Globals.ThisWorkbook.InnerObject)).Activate +=

        new Excel.WorkbookEvents_ActivateEventHandler(ThisWorkbook_Activate);




    For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.