Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jun 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoOpen macro not running (Word 97 SR-2)

    I

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    Did you make AutoOpen a Public Sub?

    Is the document attached to the particular template?

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    I don't remember the details of the macro security in Word 97, but in 2000 there is a somewhat intricate interaction between the location of the template (e.g., user's template folder, workgroup template folder, anywhere else), the "trust installed templates" checkbox, and the level of macro security. See if you can work these settings to the point that the AutoOpen will run.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    Hi Richo:
    If your document is in Page Layout view, your fields in the footer should update because Word repaginates automatically. If you work in normal view, they won't update unless you check the box in Tools/Options/General/background repagination.

    i.e. You shouldn't need a macro to update the field.

  5. #5
    New Lounger
    Join Date
    Jun 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    Howard

    I changed it from Sub to Public Sub - still no good. The text of the macro is as follows:

    Public Sub AutoOpen()

    Application.ScreenUpdating = False
    With ActiveDocument.Windows(1).View
    .Type = wdNormalView
    .Type = wdPageView
    End With
    Application.ScreenUpdating = True

    End Sub

    The template is stored in a Templates folder on a shared drive. (I have tried putting the template on my local drive then opening a document attached to it - no luck)

    Do I have to do someting in Tools/Options/File Locations? I currently have nothing listed next to Workgroup Templates

    Richo

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    1. <LI>Does the macro run? If you add a MsgBox "AutoOpen Running" you should be able to know for sure.

      <LI>What if you use an alternative approach of updating the fields collections?
      <pre>Sub UpdateAllFields()
      'Visit all of the story ranges in the ActiveDocument
      Dim rng As Range
      For Each rng In ActiveDocument.StoryRanges
      rng.Fields.Update
      Next
      If ActiveDocument.Sections.Count = 1 Then Exit Sub
      'Headers and footers after the first section are not
      ' covered by the story ranges; visit them individually
      Dim sect As Section, hdrftr As HeaderFooter
      For Each sect In ActiveDocument.Sections
      For Each hdrftr In sect.Headers
      hdrftr.Range.Fields.Update
      Next
      For Each hdrftr In sect.Footers
      hdrftr.Range.Fields.Update
      Next
      Next
      End Sub</pre>
    Hope this helps.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    I put the following in an arbitrarily chosen Wurd template:

    <pre>Public Sub AutoOpen()
    Application.ScreenUpdating = False
    MsgBox "Damn!!!"
    With ActiveDocument.Windows(1).View
    .Type = wdNormalView
    .Type = wdPageView
    End With
    Application.ScreenUpdating = True
    End Sub
    </pre>


    Then I created a new document based on that template.
    Saved the document at some location, say, in My Documents.
    Exited Word.

    Double clicked on the just saved document.
    Worked as expected.

    Off the top of my head on this very bad day, I could guess that you have the template
    saved in some directory that is not searched by Word when a doc is opened,
    in which case, the template won't be found.

    You can test that hy[pthesis easily.

    1. Exit Word.
    2. Double click on the document.
    3. Start the VBIDE to see if the template is actually opened and contains the code.

    I suspect that either the template is not being activated or the code is not in the template.

  8. #8
    New Lounger
    Join Date
    Jun 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    Howard
    Tried the Damn! Msg Box - it came up, so the macro was running, but it wasn't updating the field
    I then changed the macro so that it just sets the page to Normal view. User then has to manually choose page layout view (if they want to), which then shows the NumPages field updated. So I guess this is a fix!

    Thanks for everyone's help
    Richo

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoOpen macro not running (Word 97 SR-2)

    Does this do what you want, i.e., does it cause the field to be updated?

    <pre>Public Sub AutoOpen()

    ' Application.ScreenUpdating = False
    ' MsgBox "Damn!!!"
    ' With ActiveDocument.Windows(1).View
    ' .Type = wdNormalView
    ' .Type = wdPageView
    ' End With
    ' Application.ScreenUpdating = True

    With ActiveDocument
    Application.ScreenUpdating = False
    If Not .Saved Then
    .Repaginate
    End If
    Application.ScreenUpdating = True
    End With
    End Sub
    </pre>


Posting Permissions

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