-
Solved: Styling Matching Paragraphs
Trying to come up with effecient way to find all that paragraphs that equal all of an input text and apply an input style to the entire paragraph
I was hoping to avoid looping through all the .Paragraphs matching text. Just not elegant
So far ...
[vba]
Sub drv()
Call MatchPara("one")
Call MatchPara("two")
Call MatchPara("three")
End Sub
Sub MatchPara(sFind As String, Optional sStyle As String = "Heading 1")
Application.StatusBar = "Marking '" & sFind & "' in " & sStyle
With ActiveDocument.StoryRanges(wdMainTextStory).Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.sTyle = ActiveDocument.Styles("Heading 1")
.Text = sFind & "^p"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
[/vba]
1. Using .Text = sFind & "^p" works UNLESS sFind happens to be the last text in the previous para
Works: NoNoNo^pYes^p formats the Yes in the right style
Does not work: NoNoNoMaybeMaybeYes^pYes^p incorrectly formats NoNoNoMaybeMaybeYes
2. Using .Text = "^p" & sFind & "^p" incorrectly formats the previous paragraph in the style
I'm hoping there are some switches I don't know about. I tried using WildCards, but never hit the right combination I guess
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules