Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Normal.dot Footer (VB 6.3/MSWord/2003)

    (Edited by HansV to provide link to post- see <!help=19>Help 19<!/help>)

    Hi everyone,

    A while back, I posted a problem I was having with normal.dot (<post#=450550>post 450550</post: >) where footers within Word weren't automatically updating (i.e., the filename and path field still showed normal.dot when actually just working in a blank document).

    At the time, I thought I had a solution, however, I didn't so I placed a support call with Microsoft. I asked if they could let me know how to update fields within a document when a user saves, opens and closes a document. They came back to me with the code in the attached .txt files. I am now, however, plagued with complaints from users, and have realised that when the 10 minute autosave occurs, ALL fields within documents are updating - all of our documents contain fields for page numbers, filename and path (within the footer), tables of contents and sometimes cross-referencing, so you can imagine that that is a problem for users, especially if documents are sizeable.

    I've come to the conclusion that the best thing to do is to make sure that fields update when a user opens/closes a document, of if they run a new document so I've added the following code into AutoNew, AutoOpen and AutoClose subs within Normal:

    For Each aStory In ActiveDocument.StoryRanges

    For Each aField In aStory.Fields
    aField.Update
    Next aField

    Next aStory

    This seems to work well, however, I'd also like to add this code to AutoExec, the problem is, it appears that the code is running before a document has loaded - does anyone know if I can add a delay so that the code executes after the document is loaded? Also, would it be possible to narrow the code down so that only the filename and path field updates, rather than all fields in general?

    Thanks in hope,

    Violet

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Normal.dot Footer (VB 6.3/MSWord/2003)

    AutoExec is run in Normal.dot and in add-ins when they are loaded, i.e. when Word starts, so I don't see why you would want to update fields in AutoExec.

    You can check the field type in the inner loop:

    For Each aField In aStory.Fields
    If aField.Type = wdFieldFileName Then
    aField.Update
    End If
    Next aField

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Normal.dot Footer (VB 6.3/MSWord/2003)

    My understanding (which is most likely wrong, I've never had any VB training and only pick things up as I go along, admitedly not very well) is that autoexec runs when Word is opening and loading the global template, so I thought that having that code should mean that the footer in the new blank document should reflect the fact that it is document 1, however, at the moment when I open Word, the blank document 1 footer still reflects 'normal.dot'.

    I'll try adding in the code for the filename field just now though, thanks for that.

    Regards,

    Violet

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Normal.dot Footer (VB 6.3/MSWord/2003)

    You could create an application-level event handler for this; you wouldn't need the Document_New and Document_Open code any more.
    <UL><LI>Make sure that Word is not active.
    <LI>Make a copy of Normal.dot, so that you can go back if you don't like the following solution, or if things go wrong.
    <LI>Start Word.
    <LI>Activate the Visual Basic Editor (Alt+F11).
    <LI>Click on Normal in the Project Explorer.
    <LI>Select Insert | Class Module.
    <LI>Set the (Name) property of the class module to clsEvent (in the Properties pane).
    <LI>Type or copy the following code into the class module:

    Public WithEvents app As Application

    Private Sub app_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    Dim aStory As Range
    Dim aField As Field
    On Error Resume Next
    For Each aStory In Doc.StoryRanges
    For Each aField In aStory.Fields
    If aField.Type = wdFieldFileName Then
    aField.Update
    End If
    Next aField
    Next aStory
    Set aField = Nothing
    Set aStory = Nothing
    End Sub

    <LI>Select Insert Module.
    <LI>Type or copy the following code into the module:

    Public cls As New clsEvent

    Sub AutoExec()
    Set cls.app = Application
    End Sub

    <LI>Save Normal.dot.
    <LI>Quit and restart Word.[/list]You should now see Document1 (or similar) as filename in a new document, even when Word starts.

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Normal.dot Footer (VB 6.3/MSWord/2003)

    Hans,

    That is amazing - I am in awe. It works perfectly, thank you so much. I'd love to be able to put together code like that at the speed you do, I think I seriously need proper training!

    Thanks again,

    Violet

Posting Permissions

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