Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Updating all fields in all storyTypes (Word 2000)

    Good afternoon loungers

    I need to update all fields in all story type with code
    -------------------------------------------
    For Each story In ActiveDocument.StoryRanges
    For Each fld In ActiveDocument.StoryRanges.Fields
    ActiveDocument.StoryRanges.Fields.Update
    Next fld
    Next story
    ------------------------------------------

    I cant get to each field within each storytype ..
    Grrrr

    The inner loop like this works fine
    For Each fld In ActiveDocument.Fields
    ActiveDocument..Fields.Update
    Next fld

    Thanks in advance
    Geof

  2. #2
    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: Updating all fields in all storyTypes (Word 2000)

    > ActiveDocument.StoryRanges.Fields.Update

    I think this needs a counter,

    ActiveDocument.StoryRanges(intStoryNo).Fields.Upda te

    Actually, no, that creates errors for missing stories. Try this:

    Dim story As Range
    For Each story In ActiveDocument.StoryRanges
    story.Fields.Update
    Next

  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: Updating all fields in all storyTypes (Word 2000)

    Ooohh... yes... multiple sections. The StoryRanges are insufficient when there are multiple sections. They work on the first section's primary headers and footers, and first page headers and footer, and odd and even, and so forth, but ignore the headers and footers in the rest of the document.

    Now, you do not need to do anything about the LinkToPrevious property if you don't want to. If you imagine that updating your fields will be a lengthy and arduous process, then you might want to avoid doing it extra times when you don't need to. If you had a 50 section document, you would have 100 headers and footers to update. If they all were linked, you could do it twice (once for the first header and once for the first footer) and be done with it. But that's an improbable scenario, and unless your fields are OLE links, updating them should not take long.

    By the way, in your first loop, you can lose the For Each and Next; the middle line should handle the entire body text at once.

  4. #4
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    Hmm, as an aside, I've had this requirement for a long while too (you'd think updating all fields would be built in, like toggle all fields is, but there we go...), and the code I cobbled together (probably from stuff out of this MB or otherwise Woody's books) was:

    Public Sub UpdateAllFields()
    If Not Documents.Count = 0 Then
    Dim aStory As Range
    For Each aStory In ActiveDocument.StoryRanges
    While Not (aStory Is Nothing)
    aStory.Fields.Update
    Set aStory = aStory.NextStoryRange
    Wend
    Next aStory
    End If
    End Sub

    This seems to have been sufficient for my needs: does it miss out some fields and I just failed to notice them? (I must admit that since my docs are single-sided I have fewer encounters with the multiple versions of headers & footers)...

    dtw

  5. #5
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    <P ID="edit" class=small>Edited by gwhitfield on 06-Apr-02 07:22.</P>Hyperlinked

    Hi
    Thanks for the thoughts ..
    I found a solution by working on headers & footers separately

    Clues came from this site

    http://www.scottm.dircon.co.uk/vbatips/wor...ange/search.htm

    -----------
    For Each fld In ActiveDocument.Fields
    ActiveDocument.Fields.Update
    Next fld

    For Each sec In ActiveDocument.Sections
    For Each hf In sec.Headers
    bcheck = hf.LinkToPrevious
    If Not bcheck Then
    hf.Range.Fields.Update
    End If
    Next hf
    For Each hf In sec.Footers
    bcheck = hf.LinkToPrevious
    If Not bcheck Then
    hf.Range.Fields.Update
    End If
    Next hf
    Next sec
    ---------------
    Question is why does one need to do this and why the need for the boolean check on same as previous.

    Cheers
    Geof

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    This nested loop
    <pre>For Each aStory In ActiveDocument.StoryRanges
    While Not (aStory Is Nothing)
    aStory.Fields.Update
    Set aStory = aStory.NextStoryRange
    Wend
    Next aStory
    </pre>

    Seems very strange. I'm sure that it must be updating the fields in each story range multiple times. Why not just use.
    <pre>For Each aStory In ActiveDocument.StoryRanges
    aStory.Fields.Update
    Next aStory
    </pre>


    StuartR

  7. #7
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    Hi Stuart
    The problem is that only the stories in the first section are updated..

    As to why ?
    Havent got a clue.

    Geof

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

    Re: Updating all fields in all storyTypes (Word 2000)

    Look at the example in the help for the NextStoryRange property of the Range object.

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    You may also want to look at some of the replies to #119485 which have examples of how to update all headers, footers and story ranges.

    StuartR

  10. #10
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating all fields in all storyTypes (Word 2000)

    Yes, doing a quick bit of testing it looks like you're right, Stuart.
    I'll rip out those extra lines since all they seem to be doing is slowing things down a little. Odd, i'm sure I had them in there for a reason, just can't for the life of me think what it was... <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Another thing spotted during testing: switching views from Page to Normal and then back SEEMS to force Word to update all fields without us manually cycling through them: can anyone confirm that this holds true for multiple-sections, etc. etc. (could be a useful sideways solution?)

Posting Permissions

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