Reputation: 9
I want to set the whole text after a specific word in a word file to OutlineDemote.
My VBA script is setting the whole document to OutlineDemote.
What am i doing wrong?
Sub FormatFeatures()
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Test", _
Forward:=True
If myRange.Find.Found = True Then
myRange.SetRange (myRange.End), ActiveDocument.Content.End
myRange.Paragraphs.OutlineDemote
End If
End Sub
Upvotes: 0
Views: 49
Reputation: 7860
The end of the found range is within a paragraph. So you need to start the range you're working with from the beginning of the following paragraph:
Sub FormatFeatures()
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Test", _
Forward:=True
If myRange.Find.Found = True Then
myRange.SetRange myRange.Next(wdParagraph).Start, ActiveDocument.Content.End
myRange.Paragraphs.OutlineDemote
End If
End Sub
EDIT: Screenshot of results
Upvotes: 1