Results 1 to 3 of 3
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    StoryRange code (Word 2002 XP)

    I'm using "story range" code to check all the parts of a documnet ie headers and footers.

    however Im finding my story range code is not working. Should I be using something else?

    any ideas?

    diana


    Dim aStory As Range
    For Each aStory In ActiveDocument.StoryRanges

    aStory.Find.Replacement.ClearFormatting
    With aStory.Find
    .Text = strSearch
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    End With
    aStory.Find.Execute Replace:=wdReplaceAll

    Next aStory

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: StoryRange code (Word 2002 XP)

    Looping through headers and footers can be tricky, because the one-loop code (like yours) that you'd think would do the job will only visit the first header and footer of each type (i.e., the first First Page footer, the first Primary footer, and so on). If the document has more than one header or footer of any given type (i.e., at least one subsequent header or footer of that type for which Same As Previous = False), you have to add a loop within the loop to avoid skipping the subsequent ones, like this:
    <pre>For Each rngStoryFirst In ActiveDocument.StoryRanges
    Set rngStory = rngStoryFirst.Duplicate
    Do While Not (rngStory Is Nothing)

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,536
    Thanks
    3
    Thanked 147 Times in 140 Posts

    Re: StoryRange code (Word 2002 XP)

    <P ID="edit" class=small>(Edited by Andrew Lockton on 12-Dec-06 15:42. See st3333ve's reply for a more likely resolution to your problem)</P>You may need to include clearing the find formatting too. I seem to remember that if you search for formatting then the replacement of text doesn't happen. Try this aircode and check the value of your strSearch string in the immediate window.
    <pre>Dim aStory As Range
    debug.print "Searching for: " & strSearch
    For Each aStory In ActiveDocument.StoryRanges
    With aStory.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strSearch
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
    End With
    Next aStory</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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