• Preventing the auto open macro from running (Wd 2K and Wd97)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Preventing the auto open macro from running (Wd 2K and Wd97)

    Author
    Topic
    #360368

    Hello,

    I think that I have seen the answer to this question before, but I cannot find it.

    I am creating 3 templates that can be used individually. Each template has a Dcoument_New event that shows a userform to gather information. The userform will then populate the document.

    Now here is my dilemma; I am also building a 4th, master template that will be able to open and complete some or all of the other individual templates, but I need to prevent the Dcoument_New event from running on each one.

    I thought of creating two sets of templates, one with the Document_New event and one without it, but I think it is more efficient to use one template for both purposes.

    Also, I am creating this with Word 2000 SR1 for use by Word 97SR1.

    Any help is greatly appreciated.

    Have a good weekend.

    God Bless America!!

    Viewing 0 reply threads
    Author
    Replies
    • #542575

      What about something like this in the start of the coding for the Document_New:

      Dim doc As Document
      
      For Each doc In Application.Documents
        If doc.AttachedTemplate = "Master.dot" Then
          Exit Sub
        End If
      Next doc
      
      ' Rest of AutoOpen code
      • #544780

        Geoff,

        Thanks for this idea – solves a problem I had too.

        The following version casts a narrower net in that it will Exit Sub only if the most-recently opened document is based on Master.dot (which will be the case when this Document_New is being triggered from code running in Document_New in Master.dot). Not sure if this works right in Word 97 but it seems to work well in Wd2K:

        Private Sub Document_New()
        Dim oDocs As Documents
        Set oDocs = Application.Documents
        If oDocs(oDocs.Count).AttachedTemplate = "Master.dot" Then
            GoTo DocNewExit
        End If
        'rest of Document_New code can run:
        frmDemo.Show
        
        DocNewExit:
        Set oDocs = Nothing
        End Sub
        

        Gary

    Viewing 0 reply threads
    Reply To: Preventing the auto open macro from running (Wd 2K and Wd97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: