VBA select paragraphs to set style

C

caten

I'm trying to automate formatting of a Table of Contents document.

How can I use VBA to find all paragraphs that do NOT include a tab followed
by a number (page number) and change the style setting for those paragraphs?
(These are the chapters.)

I know how to change the style, but I'm not sure how to evaluate what the
paragraph "contains". I'm using Word 2002 SP3.
 
P

Pesach Shelnitz

Hi,

The following macro applies the Heading 2 style to all paragraphs in a
document that do not contain a tab followed by a number.

Sub ApplyStyleSelectively()
Dim prg As Paragraph

For Each prg In ActiveDocument.Paragraphs
If prg.Range.Find.Execute(findText:="^t^#", _
Wrap:=wdFindStop, Forward:=True) = False Then
prg.Style = wdStyleHeading2
End If
Next
End Sub
 

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