Search for Heading 1's

S

Steve Wylie

I need a short macro that will cycle through a document
looking for any paragraph in Heading 1 style that is in a
table. It can ignore any other styles within a table,
and it can ignore any Heading 1's not in a table.

If it finds one, it would be good if the macro would just
stop at that point in the document so as to draw
attention.

I did try doing this myself, but I am not really fluent
with the way Find & Replace works in Word VBA. Or should
I be looking at a "FOR EACH" solution? There are some
ideas on the www.mvps.org/word site but nothing for this.

Thanks to anyone who can help!

Steve
 
J

Jonathan West

Hi Steve,

Try something like this

With Selection.Find
.Format = true
.ClearFormatting
.Style = "Heading 1"
.Text = ""
Do While .Execute
If Selection.Information(wdWithinTable) Then
Exit Do
End If
Loop
End With

That macro will stop at the first Heading 1 style it finds within a table.
If it finds one not within a table, it will ignore it and look for the next
one.
 
S

Steve Wylie

Hello Jonathan

That sounds just what I'm looking for - thanks!

I'll try it out as soon as I get to work tomorrow.

I always find it a problem when I'm trying to write a macro that uses Find &
Replace. Do you know of any web resources/tutorials that would be of help
to a VBA beginner like me?

Steve
 
J

Jonathan West

Hi Steve,

There are quite a few samples on the Word MVPs website www.mvps.org/word/
that use Find. You might like to do a search there and take a look at the
samples.

But a short tutorial on the Find object itself sounds like a good idea for
an article for the site, and if I get a round tuit I will write one! :)
 

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