Word Macro: search for "Chapter" and apply style Heading 2 to paragraph
//---CODE---//
Sub FormatParagraphsContainingText()
Dim sTextToFind As String
Dim oStyleToUse As Style
Dim oRange As Range
sTextToFind = "Chapter"
Set oStyleToUse = ActiveDocument.Styles(wdStyleHeading2)
Set oRange = ActiveDocument.Range
With oRange
'clear previous format criteria in the find dialog
.Find.ClearFormatting
.Find.Replacement.ClearFormatting
With .Find
.Text = sTextToFind
.Forward = True
.Wrap = wdFindStop
.Format = False
Do While .Execute()
'Change the style
oRange.Paragraphs(1).Style = oStyleToUse
Loop
End With
End With
End Sub
//--END-CODE--//
the bold 2 can be changed to 3 etc if required for your various indent levels
Never Deprive Anyone of Hope.. It Might Be ALL They Have
Comments
-
Nice piece of code Dominic!
i have added it to Tools and Files supplied by users wiki page
0 -
Maybe this is different but in Word 2010 in the Find and replace feature I can serarch for Font Size 12 Bold and Replace with Heading 1. In the Replace Box I choose ^& (Find what text) in the Special Section and then under format I choose style and then Heading 1. Most chapter heading are larger font then the rest of the text. If that is not the case then you can search for certain terms and replace with Heading styles.
0 -
useful to know John, I only have word 2007, so am lacking in features, but I did this because I mostly deal with plain text conversion so sadly no formatting,,
Never Deprive Anyone of Hope.. It Might Be ALL They Have
0