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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top