NextStoryRange Property Example

This example adds text to the even headers in the first two sections in the active document.

If ActiveDocument.Sections.Count >= 2 Then
    With ActiveDocument
        .PageSetup.OddAndEvenPagesHeaderFooter = True
        .Sections(1).Headers(wdHeaderFooterEvenPages) _
            .Range.Text = "Even Header"
        .Sections(2).Headers(wdHeaderFooterEvenPages) _
            .LinkToPrevious = False
        .StoryRanges(wdEvenPagesHeaderStory) _
            .NextStoryRange.Text = "Even Header 2"
    End With
End If

This example searches each story in the active document for the text "Microsoft Word." The example also applies italic formatting to any instances of this text that it finds.

For Each myStoryRange In ActiveDocument.StoryRanges
    myStoryRange.Find.Execute  _
        FindText:="Microsoft Word", Forward:=True
    While myStoryRange.Find.Found
        myStoryRange.Italic = True
        myStoryRange.Find.Execute  _
            FindText:="Microsoft Word", Forward:=True
    Wend
    While Not (myStoryRange.NextStoryRange Is Nothing)
        Set myStoryRange = myStoryRange.NextStoryRange
        myStoryRange.Find.Execute  _
            FindText:="Microsoft Word", Forward:=True
        While myStoryRange.Find.Found
            myStoryRange.Italic = True
            myStoryRange.Find.Execute  _
                FindText:="Microsoft Word", Forward:=True
        Wend
    Wend
Next myStoryRange