Share via

Autoopen

Anonymous
2023-07-14T17:18:15+00:00

I’ve a template file named Cards.dotm. Within ThisDocument is Public Sub Autoopen() which sets up key binding etc and also message box to confirm the subroutine has been processed. If I open the template document itself to make modifications, it runs the subroutine.

If I open Word then select Cards from the available templates, it displays Document1 but doesn’t run Autoopen. Other subroutines within the template file run as expected.

However, if I save Document1 (it adds suffix docx) `and then re-open it, Autoopen now runs correctly.

I’ve tried moving the Template to various locations so it doesn’t appear to be a security issue related to location: any suggestions?

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-07-15T16:26:15+00:00

    Hello,

    Unfortunately, I don't have any further troubleshooting to offer.

    There are many knowledgeable users active on the forum and I hope that someone else can offer further insight into your issue.

    Thanks.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-07-15T07:39:39+00:00

    Hi Taiwo

    Thanks for your lucid instructions.

    Trust Centre Settings are already set to: -
    Enable all macros (not recommended)
    Developer Macro Settings - Trust access to the VBA project object model.

    Amending the name AutoOpen to Document_Open produced the same error.
    Likewise creating MyAutoOpen in a module and calling from AutoOpen

    Open with is already set to Word and the Default Programs for .dotm to Microsoft Word Macro‑Enabled-template.

    I have tried copying the template file and running it from other Trusted Locations without success. With regard to "AutoOpen" can conflict with certain Word features or behaviours, I was wondering if the problem had anything to do with my key binding code, but it doesn’t.

    Going back to basics: -
    Open a blank document and type “Test 1”

    Open VBEditor and in ThisDocument, create a subroutine

    Sub Document_Open()
    Msgbox “Macro run at start-up”
    End Sub

    Save file as Test.dotm
    Location e.g. C:\Users\tom\AppData\Roaming\Microsoft\Templates

    Right-click Test.dotm and select open.
    Message displayed “Macro run at start-up”
    Close file

    Double-click Test.dotm
    Displays Document1 with text “Test 1” but there is no message from Message box.
    Ament text “Test 1” to “Test failed”, press Ctrl+W and click Save

    Open TestFailed.docx
    It now runs the start-up subroutine the message box displaying “Macro run at start-up”.

    I’m running the home version of 365 on a Dell Inspiron 3502 laptop allowing updates to install. There are no subroutines in the file Normal.dotm

    Kind Regards
    Tom

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-07-14T17:53:33+00:00

    Hi,

    I'm Taiwo and I'd be happy to help you with your question. In this Forum, We are Microsoft consumers just like yourself.

    It seems like you're experiencing an issue with the AutoOpen subroutine not running when opening a new document based on the template file "Cards.dotm" directly from the template selection in Word. However, the AutoOpen subroutine runs correctly if you save the document and reopen it. Here are a few suggestions to help resolve this issue:

    1. Verify that your macro security settings in Word allow the execution of macros. Go to Word Options, click on "Trust Center" and then "Trust Center Settings." Ensure that macro settings are not set to "Disable all macros" but rather to "Enable all macros" or "Disable all macros with notification." This will ensure that macros are allowed to run without restrictions.
    2. Sometimes, the name "AutoOpen" can conflict with certain Word features or behaviours. Try renaming the subroutine to something unique, such as "MyAutoOpen," and update any references to it accordingly within your template file. This can help avoid any conflicts and ensure that the subroutine is triggered correctly.
    3. Instead of relying on the AutoOpen subroutine, you can use the Document Open event to achieve the desired behaviour. Create a new subroutine within the template file named "Document_Open" (note the underscore) and place your code inside that subroutine. This event will trigger whenever the document is opened, regardless of whether it is a new or existing document.
    4. Make sure that the file association for .dotm files is correctly set to Microsoft Word. To do this, right-click on the template file "Cards.dotm," choose "Open with," and select Microsoft Word from the list of available programs. Additionally, you can try associating .dotm files with Word by default through your computer's file association settings.

    I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

    Best Regards, Thank You.

    Was this answer helpful?

    0 comments No comments