Apply a user-defined paragraph style under certain conditions.

A

andreas

Dear Experts:

I would like to have a macro that

.... loops thru all the paragraphs of my document and as soon it hits a
paragraph that starts with the text "Page" a user-defined paragraph
style is to be applied.

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
 
G

Graham Mayor

The following should work - replace "Stylename" with the required style name

Dim oRng As Range
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
For i = oStory.Paragraphs.Count To 1 Step -1
Set oRng = oStory.Paragraphs(i).Range.Words(1)
If Trim(oRng.Text) = "Page" Then
oStory.Paragraphs(i).Range.Style = "Stylename"
End If
Next i
Next oStory

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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