Code to determine if a line is "Centered"

S

Sophia

Hello ...

I have an *.rtf document open in Word97 with a series of "centered"
paragraphs at the beginning of each section. After the "centered"
lines, there is a long series of paragraphs that are left justified.
This pattern repeats itself through many pages (i.e. a series of
"centered lines" followed by another series of lines that are
left-justified).

Could you help me with the VB that reads each paragraph to determine
if it's "centered", then reads the group of "centered" lines until it
finds the last one (before the left-justified ones start) and inserts
a bookmark at the beginning of that line?

After that, I'd like it to do the same until it reaches the end of the
document. (There wouldn't be more than 20 such sections in the
document).

TIA
 
D

Doug Robbins - Word MVP

The following does what you want:

Dim flag1 As Boolean, flag2 As Boolean, i As Long, bmrange As Range
flag1 = True
flag2 = False
For i = 1 To ActiveDocument.Paragraphs.Count
If ActiveDocument.Paragraphs(i).Alignment = wdAlignParagraphCenter Then
flag1 = True
flag2 = False
Else
flag1 = False
End If
If flag1 = flag2 Then
Set bmrange = ActiveDocument.Paragraphs(i).Range
bmrange.Collapse wdCollapseStart
ActiveDocument.Bookmarks.Add "Bookmark" & i, bmrange
flag1 = True
flag2 = True
End If
Next i


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
S

Sophia

Bless you Doug ...

I'm on my way to seeing how it works.

I *did* do my Usenet homework on this one, but came up tangled in more
code than you can imagine ...

Thanks ...

Sophia
 

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