• Updating all fields in all storyTypes (Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Updating all fields in all storyTypes (Word 2000)

    • This topic has 9 replies, 5 voices, and was last updated 23 years ago.
    Author
    Topic
    #369181

    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

    Viewing 1 reply thread
    Author
    Replies
    • #580652

      > ActiveDocument.StoryRanges.Fields.Update

      I think this needs a counter,

      ActiveDocument.StoryRanges(intStoryNo).Fields.Update

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

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

      • #580654

        Edited by gwhitfield on 06-Apr-02 07:22.

        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%5B/url%5D

        ———–
        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

        • #580658

          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.

          • #580744

            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

            • #580839

              This nested loop

              For Each aStory In ActiveDocument.StoryRanges
                  While Not (aStory Is Nothing)
                        aStory.Fields.Update
                        Set aStory = aStory.NextStoryRange
                  Wend
              Next aStory
              

              Seems very strange. I’m sure that it must be updating the fields in each story range multiple times. Why not just use.

              For Each aStory In ActiveDocument.StoryRanges
                   aStory.Fields.Update
              Next aStory
              

              StuartR

            • #580890

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

              As to why ?
              Havent got a clue.

              Geof

            • #580933

              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

            • #581094

              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… confused
              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?)

    • #580932

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

    Viewing 1 reply thread
    Reply To: Updating all fields in all storyTypes (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: