Greg
Fri Mar 16 23:55:56 CDT 2007
LEU,
AFAIK, you can't use a Replacement and wdReplaceAll for this purpose. You
need to find, evaluate and as appropriate manipulate the found range using a
While .Execute statement:
Sub Test()
Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
.Text = "Order"
While .Execute
Select Case SearchRange.Style
Case "Heading 1", "Heading 2", "Heading 3", "Heading 4"
SearchRange.Font.AllCaps = True
SearchRange.Font.Bold = True
Case Else
'Do Nothing
End Select
Wend
End With
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
LEU wrote:
> I have the following macro that finds the word 'Order' and changes it
> to all caps and bold in the whole document. How do I change it to
> just replace it in my ActiveDocument.Styles "Heading 1", "Heading 2",
> "Heading 3" and "Heading 4"?
>
> Dim SearchRange As Range
> Set SearchRange = ActiveDocument.Range
> With SearchRange.Find
> .ClearFormatting
> .Replacement.ClearFormatting
> .Forward = True
> .Format = True
> .Wrap = wdFindContinue
> .Replacement.Font.Bold = True
> .Text = "Order"
> .Replacement.Text = "ORDER"
> .Execute Replace:=wdReplaceAll
> End With