Consulting

Results 1 to 3 of 3

Thread: Open Word Template, and have THAT file's Userform open

  1. #1
    VBAX Regular
    Joined
    Jul 2018
    Posts
    9
    Location

    Open Word Template, and have THAT file's Userform open

    Hi there,

    I have a main excel document that gathers data, it has a command button that opens a Word Letter template. That word document has a userform that "should" open when that word template opens. Is there a way I can open the word document AND it's userform when that word document opens?
    This is the code in my excel file that open's the word template
    Private Sub CommandButton11_Click()
    Set appWD = CreateObject("Word.Application")
    appWD.Visible = True
    appWD.Documents.Open Filename:="C:\Users\Documents\Custom Office Templates\Letter 0219.dotm"
    End Sub
    Here is the code in Word template that opens the Userform when the document is open
    Option Explicit
    Dim oFrm As Userform1
    Sub AutoNew()
      Set oFrm = New Userform1
      With oFrm
        .Show
        If .Tag = "CREATE DOC" Then
          FillDoc
        Else
          ActiveDocument.Close wdDoNotSaveChanges
        End If
      End With
    lbl_Exit:
      Exit Sub
    End Sub

  2. #2
    This question seems to have been overlooked, but the issue you have here is that the template is being opened rather than a new document created from it, so changing the following line as shown should cause the autonew macro to fire (or if you really want to open the template, add an AutoOpen macro to the template to fire when the template is opened.

    Or you could add the line
    appWD.Run ("AutoNew")
    to the first of the following:

    Change
    appWD.Documents.Open Filename:="C:\Users\Documents\Custom Office Templates\Letter 0219.dotm"
    to
    appWD.Documents.Add Template:="C:\Users\Documents\Custom Office Templates\Letter 0219.dotm"
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jul 2018
    Posts
    9
    Location
    Perfection! thank-you so much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •