none
Excel's WorkbookOpen event doesn't fire when excel & workbook is opened from command line RRS feed

  • Question

  • In ThisAddIn_Startup I register for WorkbookOpen

    (Application.WorkbookOpen += new Excel.AppEvents_WorkbookOpenEventHandler(Application_WorkbookOpen); )  If I double click a file from Windows Explorer the event fires.  If I launch the same file from the command line "EXCEL myWorkbook.xlsx", Excel and the workbook opens and I see my trace output for ThisAddIn_Startup but the handler for WorkbookOpen does not get called.  I can also reproduce the WorkbookOpen not getting called when launched from an application by using,

    ProcessStartInfo^ procStartInfo = gcnew ProcessStartInfo();
    procStartInfo->FileName = "EXCEL";
    procStartInfo->Arguments = "\"" + gcnew String(filename) + "\"";
     
    Process^ newProcess = Process::Start(procStartInfo);

    Is there a known workaround for my issue?

    Byron

    Tuesday, July 24, 2012 7:26 PM

Answers

  • Hi byronasdf,

    Thanks for posting in the MSDN Forum.

    I can reproduce your issue on my side. When I retrieve my monitor log in my add-in, I can see that WorkbookOpen has been subscribe when add-in load. And when I open other workbook after run your snippet. It works fine. It's based on my experience that you are able to add a macro to the Workbook and subscribe your WorkbookOpen event in VBA project. It will work.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by byronasdf Friday, July 27, 2012 9:39 AM
    Wednesday, July 25, 2012 5:49 AM
    Moderator
  • using this will cause the workbook_open event to fire.

    ProcessStartInfo^ procStartInfo = gcnew ProcessStartInfo();
    procStartInfo->UseShellExecute = true;
    procStartInfo->Verb = "open";
    procStartInfo->FileName = "C:\MyExcelWkBk.xlsx";


    Byron

    • Marked as answer by byronasdf Wednesday, August 1, 2012 12:39 AM
    Wednesday, August 1, 2012 12:39 AM

All replies

  • Hi byronasdf,

    Thanks for posting in the MSDN Forum.

    I can reproduce your issue on my side. When I retrieve my monitor log in my add-in, I can see that WorkbookOpen has been subscribe when add-in load. And when I open other workbook after run your snippet. It works fine. It's based on my experience that you are able to add a macro to the Workbook and subscribe your WorkbookOpen event in VBA project. It will work.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by byronasdf Friday, July 27, 2012 9:39 AM
    Wednesday, July 25, 2012 5:49 AM
    Moderator
  • Thanks for the reply Tom,

    Should I log a bug with Microsoft's Connect site?

    I'm rewriting our current Office integration using vsto so I can get away from using Macros and Automation.  The current solution uses WCF to allow the applicaiton communicate with the Excel add-in.  After I launch Excel and the workbook, I can have the application send a message to the add-in telling add-in that a workbook has been opened.  The add-in will loop through Application.Workbooks and verify that all open workbooks are known about by the add-in.  Basically create my own Workbook_Open event.


    Byron

    Wednesday, July 25, 2012 12:35 PM
  • Hi Byron,

    I recommend you do that. And I will submit it in internal channel. I think it can help product group to improve Office's quality.

    Thaks for you post.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 27, 2012 6:23 AM
    Moderator
  • using this will cause the workbook_open event to fire.

    ProcessStartInfo^ procStartInfo = gcnew ProcessStartInfo();
    procStartInfo->UseShellExecute = true;
    procStartInfo->Verb = "open";
    procStartInfo->FileName = "C:\MyExcelWkBk.xlsx";


    Byron

    • Marked as answer by byronasdf Wednesday, August 1, 2012 12:39 AM
    Wednesday, August 1, 2012 12:39 AM