Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Updating all fields, including headers & footers

    I want to update all fields in the document including those in header and footer. I thougt this would work:

    For Each objStory In ActiveDocument.StoryRanges
    objStory.Fields.Update
    If objStory.StoryType <> wdMainTextStory Then
    While Not (objStory.NextStoryRange Is Nothing)
    Set objStory = objStory.NextStoryRange
    objStory.Fields.Update
    Wend
    End If
    Next objStory
    Set objStory = Nothing

    BUT only updates fields in the body. So I found this that HansV had posted:

    For Each objStory In ActiveDocument.StoryRanges
    Do
    objStory.Fields.Update
    Set objStory = objStory.NextStoryRange
    Loop Until objStory Is Nothing
    Next objStory

    BUT same again. How do I get the header & footer fields to update (objStory is defined as a range).

    Thanks........... liz

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

    Re: Updating all fields, including headers & footers

    Could you post a small sample document in which not all fields eare updated by the code?

  3. #3
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Updating all fields, including headers & foote

    Hans,

    3 pages but little content the headers & footers are from section 2 page 2. I'm sure it's obvious if you know!

    thank you................... liz

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

    Re: Updating all fields, including headers & foote

    Try this code, it is more dependable (and shorter too):

    Application.ScreenUpdating = False
    ActiveDocument.PrintPreview
    ActiveDocument.ClosePrintPreview
    Application.ScreenUpdating = True

  5. #5
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Updating all fields, including headers & foote

    Thank you!

  6. #6
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: 2003Updating all fields, including hdr & ftr

    Hans,

    Have come back to this. I think I spoke in haste previously. No only does this not upadte the fields - any of them either the body or the headers & footers. When I select print preview manually this also does not update the fields. My options are set to update fields on print and this works. So I can't think of anything else that would inhibit updating. And it isn't only on my machine and I've tested with a document created using the delivered Normal but no luck.

    What have I done? n.b. I am on Word 2003

    thank you.... liz

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

    Re: 2003Updating all fields, including hdr & ftr

    I admit I'm stumped. The code I posted has worked for years (at least since Word 97), but it doesn't now, neither in the document you posted, nor in a small test document I created. The only way left seems to be to actually print out the document. To avoid wasting paper, you could print to a file.

    Sorry! <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  8. #8
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: 2003Updating all fields, including hdr & ftr

    Hans,

    Ok so nothing works! My users get very nervous when they don't see their changes, and whilst I can educate some of them some are just nervous and some are temporary so it will always be a problem.

    I've gone back to this version of code, which almost seems to work always:

    For Each objStory In ActiveDocument.StoryRanges ' update all fields, including header & footer
    Do
    objStory.Fields.Update
    Set objStory = objStory.NextStoryRange
    Loop Until objStory Is Nothing
    Next objStory
    Set objStory = Nothing

    EXCEPT it doesn't touch the headers & footers. Can you think of a way of forcing this?

    Thanks..... liz

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

    Re: 2003Updating all fields, including hdr & ftr

    Nope, as I wrote, I'm stumped. Sorry.

  10. #10
    New Lounger
    Join Date
    Jul 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2003Updating all fields, including hdr & ftr

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Hi Liz (& Hans),

    Try this version which I got from here: http://gregmaxey.mvps.org/Field_Macros.htm.
    <pre>Sub myUpdateFields()
    Dim pRange As Word.Range
    Dim iLink As Long
    iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype
    For Each pRange In ActiveDocument.StoryRanges
    Do
    pRange.Fields.Update
    Set pRange = pRange.NextStoryRange
    Loop Until pRange Is Nothing
    Next
    End Sub
    </pre>

    I vaguely recall seeing postings in newsgroups some time ago about a bug in Word; can't quite remember the details but it was something to do with the fact that if Word encountered an empty header (or footer?) then it would fail to update fields in subsequent headers (and footers?). And I think a workaround was found by a Peter Hewett.

    I think the workaround is this:

    Dim iLink As Long
    iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype

    Don't know exactly what it does but from stuff I've read it seems to work.

    Regards.

    Ed

Posting Permissions

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