Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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!!

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    What about something like this in the start of the coding for the Document_New:<pre>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</pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

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

    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:

    <pre>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
    </pre>

    Gary

Posting Permissions

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