You misunderstand how the Range.Find object works. First you set all
the necessary properties of the .Find object -- .Text, .Style,
..Format, .Wrap, and so on -- and then you call .Execute. In your
macro, you never set any properties of SearchRange.Find, so calling
..Execute did nothing at all.
When you want to search for a batch of styles, one way is to put them
into an array, and then loop through the array to search for each one
in turn:
Dim SearchRange As Range
Dim StyleList As Variant
Dim i As Integer
StyleList = Array("Heading 1", "Heading 2", "Heading 3", _
"Heading 4", "Heading 5", "Heading 6", "Heading 7")
For i = 0 To UBound(StyleList)
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
.Text = ""
.Style = ActiveDocument.Styles(StyleList(i))
.Format = True
While .Execute
SearchRange.ParagraphFormat.RightIndent = _
InchesToPoints(0.4)
Wend
End With
Next i
A related way is to put all the search items into a collection. Then
you can use a For Each loop instead of an explicit loop counter:
Dim SearchRange As Range
Dim StyleList As New Collection
Dim thisStyle As Style
With StyleList
.Add ActiveDocument.Styles("Heading 1")
.Add ActiveDocument.Styles("Heading 2")
.Add ActiveDocument.Styles("Heading 3")
.Add ActiveDocument.Styles("Heading 4")
.Add ActiveDocument.Styles("Heading 5")
.Add ActiveDocument.Styles("Heading 6")
.Add ActiveDocument.Styles("Heading 7")
End With
For Each thisStyle In StyleList
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
.Text = ""
.Style = thisStyle
.Format = True
While .Execute
SearchRange.ParagraphFormat.RightIndent = _
InchesToPoints(0.4)
Wend
End With
Next
Finally, it would be _much_ simpler -- no macro at all -- to modify
the definitions of the heading styles. That would affect all the
headings in the document at once, including headings that you add to
the document later (which the macro methods wouldn't affect).
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.