Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word: How to Find each Paragraph and work with it 1

Status
Not open for further replies.

GPerk

Programmer
Jul 6, 2002
161
US
I have a Word doc which has some paragraphs which start with a number followed by a period. Example "21. Text..."
If a numbered paragraph is found, I want to do some work with that paragraph - such as find certain words in that paragraph and upcase them.
How can I set up the loop thru the paragraphs and work with each paragraphs? I am trying:

N=ActiveDocument.Paragraphs.Count
For I = 1 to N
if Paragraphs(I) begins with "[0-9]{1,2,3}." then ?How??
Do some Finds here, restricted to this paragraph ?How?
end if
Next I

I think I have to set the range to each paragraph, but how?
Can I do a wildcard test for the beginning of the paragraph?

 
Hi GPerk,

You're nearly there ...

The paragraph text is in ActiveDocument.Paragraphs(I).Range.Text and if your number is space-separated from the rest of the paragraph text you can use ActiveDocument.Paragraphs(I).Range.Words(1). So you could say ..

If IsNumeric(ActiveDocument.Paragraphs(I).Range.Words(1)) Then ...

Exactly what you do depends on exactly what you have but I'm afraid I don't know of any way of using wild cards.

Enjoy,
Tony
 
I j ust found out you can use Like in Word the same way you can in SQL so for a wildcard check to see if the first character is numeric you could do ...

Code:
If ActiveDocument.Paragraphs(I).Range.Text Like "#*" Then ...

Enjoy,
Tony
 
Thanks, Tony.
Your suggestions have been most helpful.
Gene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top