Step through document to make headers

Y

ybazizi

I have a document that is about 600 pages long that I need to
programmatically make headers (Heading 1, Heading 2, Heading 3...) I want to
be able to step through a document line by line and read the contents of the
beginning of each line, and if it matches a certain text, make that line a
header. Is there any simple way I can use a loop to do this?

Thanks,

J
 
G

Greg Maxey

Not saying this is the best way, but something like this might do:

Sub Test()
Dim oPar As Paragraph

For Each oPar In ActiveDocument.Paragraphs
If InStr(oPar.Range.Text, "Match this text") = 1 Then
oPar.Style = "Heading 1"
End If
If InStr(oPar.Range.Text, "Match some other text") = 1 Then
oPar.Style = "Heading 2"
End If

Next oPar

End Sub

Replace "Match this text" and "Match some other text" with the certain text
you had in mind.
 
Y

ybazizi

Thanks Greg - that was exactly what I needed. I just needed a good example
of the way to use the Range object.

J
 

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