Auto displaying form on opening a template file, dotm from explorer

14,611

In the "generator.dotm" file got to Visual Basic and go in to the "ThisDocument" Microsoft Word Object.

At the top of the Visual Basic Editor select "Document" in the left hand side and then click on "New" on the right hand side. Private Sub Document_New() method will appear for you to be able to edit. Then you can call your userform in there. Similar to:

Private Sub Document_New()

    Dim myForm As UserForm1
    Set myForm = New UserForm1

    myForm.Show

End Sub

Save your Generator.dotm and double click it through Windows explorer and you should get the results that you would like.

Share:
14,611
Admin
Author by

Admin

Updated on June 17, 2022

Comments

  • Admin
    Admin almost 2 years

    I have written a form based document generation macro (in VBA) for distribution to a sales team.

    For their ease of use, I want to provide a self-contained file which will display the form as soon as the document is opened.

    Using AutoOpen I can get the form to display as intended if word is already open and the dotm file is opened within. However, if I double click the file from within explorer, nothing happens and I have to launch the macro manually. I thought AutoExec might allow this but no luck there. I've spent considerable time trying to get this to work through googling etc. but I'm not getting anywhere.

    How can I make the form display even when the file is opened with a double click? Is it possible to do this without having to change normal.dotm for each user?

    For further background, I am using Word 2013 with macros fully enabled during testing. The dotm file is stored in a trusted location.

    I am using a macro to launch the form like this...

    Public Sub AutoOpen()
        StartPage.Show
    End Sub
    

    I have tried using AutoExec as well to no avail.