none
C#: Checking if Excel workbook Open event finishes. RRS feed

  • Question

  • I have a macro-enabled workbook that has code attached to the Workbook_Open event. I am writing a C# program. I want the program to open the workbook, wait for the Open event to finish, then save the workbook and close it. This is because the Open event performs some update operations that are needed on a fairly regular basis. 

    Currently, I open the workbook, then I save it and close it. Is there a way that I can verify that it completed the Workbook_Open event before saving and closing? I checked for a Workbook.Opened function but could not find anything.

    Tuesday, November 8, 2016 7:46 PM

Answers

  • This seems to happen automatically. Never mind! I just ran some tests, and it appears that it is running the macro without any issue.
    Tuesday, November 8, 2016 10:36 PM

All replies

  • This seems to happen automatically. Never mind! I just ran some tests, and it appears that it is running the macro without any issue.
    Tuesday, November 8, 2016 10:36 PM
  • Hi SlipEternalRobert,

    its good to know that your issue is resolved now.

    but then also if you want to know how you can try to do something then you can set the flag variable.

    and changed its value after you complete your modifying the workbook.

    so that you can know that your operation is successfully done and now you can save and close the workbook.

    or you can try to call the "Workbook_BeforeClose" event at the end of the workbook_open event.

    and do whatever you want so that when that event execute you can know that workbook_open event is already executed.

    you had mentioned that in VBA you are doing some update operations and you are trying to save and close workbook from c#. you can also do that with VBA. so after that you not need to worry about the event.

    Hope you get the idea by this. if you want any further help then let me know about that.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 9, 2016 6:03 AM
    Moderator