Autotext entry based on style

C

Cissy

Hi,

We're using Word 03. We have long documents that consist of paragraphs
formatted with a particular style. We need to insert an Autotext entry
directly above each of these paragraphs (there can be 100s of them). I know
how to use loops, but how do I refer to all of the the particular paragraphs?
I know I can use Find...but I was wondering if there's a better way. Thanks
for your help.
 
M

Martin

Hi Cissy

The following should do the trick (it uses a For...Each loop, great for
looping through collections of objects in VBA rather than the usual
For...Next loop that can only use a variable). Replace "Heading 2" and "Best
regards," with the style and autotext entry you need and you can obviously
extend the If with ElseIfs to accomodate all your other styles and entries
within the one loop:

Sub SelectByStyle()
Dim myPara As Paragraph
For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = "Heading 2" Then
myPara.Range.InsertBefore NormalTemplate.AutoTextEntries("Best
regards,") & vbNewLine
End If
Next myPara
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