Using VBA to look for Styles

B

Brian

Is there a way to move through a document until you find
text of a specific style (i.e. Header 1) and
then "capture" that text?
 
S

Steve Lang

Hi Brian,
Here ya go...

Sub FindStyle
Dim strFound as String
With Selection.Find
.ClearFormatting
.Format = True
.Forward = True
.Style = "Header 1"
.Text = ""
.Execute
End With

if Selection.Find.Found then strFound = Selection.Text

End Sub



This captures the text of the named style into a string variable (strFound)
to do with what you will.



HTH and have a great day!



Steve Lang
 
Top