none
Run code when opening Word RRS feed

  • Question

  • Thanks for taking the time to read my question.

    I want to check my references when Word opens. I put my code (that works) into "ThisDocument" of my Normal.dotm file under "Document_Open()" and "Document_New()".

    I open Word and nothing happens. BUT if I create a new blank document "Document2" then the "_New" works and if I open an existing file, the "_Open" works.

    Why does it not work when I open Word and it creates the blank "Document1" file? I expected that the "_New" would fire here.

    Thanks,
    Brad

    Monday, May 28, 2018 9:07 PM

Answers

  • You can use a macro named AutoExec for this purpose. This macro should be stored in a standard module (the type you create by selecting Insert > Module) in your Normal.dotm template.

    The AutoExec macro will be executed when Word is started.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mbrad Tuesday, May 29, 2018 2:51 AM
    Monday, May 28, 2018 9:22 PM

All replies

  • You can use a macro named AutoExec for this purpose. This macro should be stored in a standard module (the type you create by selecting Insert > Module) in your Normal.dotm template.

    The AutoExec macro will be executed when Word is started.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by mbrad Tuesday, May 29, 2018 2:51 AM
    Monday, May 28, 2018 9:22 PM
  • Hello Brad,

    That's because you subscribe to the events right after they are actually fired (too late). You may check the Documents collection at startup and imitate these events if needed.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, May 29, 2018 2:02 AM
  • Hello mbrad,

    The issue does exist. As a workaround for it, I would suggest you go to File->Options->General and then check the option "Show the Start Screen when this application starts".

    In this situation, while launching word, it will not create "Document1" directly but show a start screen first. If you create a  new blank document "Document1" from the start screen. The code will trigger.

    Best Regards,

    Terry


    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.

    Tuesday, May 29, 2018 2:21 AM
  • Hi Hans,

    This worked perfectly! thank you very much.

    Brad

    Tuesday, May 29, 2018 2:51 AM