Loop Paragraphs, if ends in ":", then bold entire paragraph

W

wleonard47

Good day,

I have been chasing my tail a bit trying various methods of moving the
selection around and can't seem to get it correct. I have many documents
that have many sections with a heading that appear like this:

Follow this process:
and/or
Begin the routing as follows:

There is no formatting to these section headings--it is just plain text.
Most of the text that follow each section are single-line paragraphs--just as
the section headings are (that should make this effort easier? right?) I
would like to loop through the paragraphs, test them for the last character
being ":" and then bold the entire line (paragraph).

I checked the board for a similar posting but did not find one. Thanks to
anyone who might provide some guidance.

Regards,
Bill Leonard
Hingham, MA
 
G

Graham Mayor

Try

Dim oRng As Range
For i = 1 To ActiveDocument.Paragraphs.Count
Set oRng = ActiveDocument.Paragraphs(i).Range
With oRng
.End = .End - 1
If .Characters.Last = ":" Then .Bold = True
End With
Next i


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tony Jollans

You should be able to do this without VBA, with a single Replace operation:

Find what: [!^13]@:^13 --- that's left (square) bracket, exclamation mark,
caret, one, three, right (square) bracket, at-sign, colon, caret, one, three

Replace with: leave empty, but with the cursor in the box, press Ctrl+B

Check "Use wildcards"

Press "Replace All"
 
W

wleonard47

Tony,

Thanks for the response. I could not get this to work--it caused Word to
hang up.

Regards,
Bill Leonard

Tony Jollans said:
You should be able to do this without VBA, with a single Replace operation:

Find what: [!^13]@:^13 --- that's left (square) bracket, exclamation mark,
caret, one, three, right (square) bracket, at-sign, colon, caret, one, three

Replace with: leave empty, but with the cursor in the box, press Ctrl+B

Check "Use wildcards"

Press "Replace All"

--
Enjoy,
Tony

www.WordArticles.com

wleonard47 said:
Good day,

I have been chasing my tail a bit trying various methods of moving the
selection around and can't seem to get it correct. I have many documents
that have many sections with a heading that appear like this:

Follow this process:
and/or
Begin the routing as follows:

There is no formatting to these section headings--it is just plain text.
Most of the text that follow each section are single-line paragraphs--just
as
the section headings are (that should make this effort easier? right?) I
would like to loop through the paragraphs, test them for the last
character
being ":" and then bold the entire line (paragraph).

I checked the board for a similar posting but did not find one. Thanks
to
anyone who might provide some guidance.

Regards,
Bill Leonard
Hingham, MA

.
 
T

Tony Jollans

It should work and does for me (on trivial test data), and hanging up is
unusual on Find & Replace. As Graham's macro works for you there probably
isn't anything much to be gained by digging into it further.

--
Enjoy,
Tony

www.WordArticles.com

wleonard47 said:
Tony,

Thanks for the response. I could not get this to work--it caused Word to
hang up.

Regards,
Bill Leonard

Tony Jollans said:
You should be able to do this without VBA, with a single Replace
operation:

Find what: [!^13]@:^13 --- that's left (square) bracket, exclamation
mark,
caret, one, three, right (square) bracket, at-sign, colon, caret, one,
three

Replace with: leave empty, but with the cursor in the box, press Ctrl+B

Check "Use wildcards"

Press "Replace All"

--
Enjoy,
Tony

www.WordArticles.com

wleonard47 said:
Good day,

I have been chasing my tail a bit trying various methods of moving the
selection around and can't seem to get it correct. I have many
documents
that have many sections with a heading that appear like this:

Follow this process:
and/or
Begin the routing as follows:

There is no formatting to these section headings--it is just plain
text.
Most of the text that follow each section are single-line
paragraphs--just
as
the section headings are (that should make this effort easier? right?)
I
would like to loop through the paragraphs, test them for the last
character
being ":" and then bold the entire line (paragraph).

I checked the board for a similar posting but did not find one.
Thanks
to
anyone who might provide some guidance.

Regards,
Bill Leonard
Hingham, MA

.
 
W

wleonard47

Hi Tony,

As it turns out, I was not properly clearing out the Search/Find dialog
after running some macros, thus leaving remnants that could affect future
searches. After cleaning up this little problem your method worked
perfectly. Getting two successful methods to use is a real bonus. Thanks
to you and Mr. Mayor once again.

Bill Leonard

Tony Jollans said:
It should work and does for me (on trivial test data), and hanging up is
unusual on Find & Replace. As Graham's macro works for you there probably
isn't anything much to be gained by digging into it further.

--
Enjoy,
Tony

www.WordArticles.com

wleonard47 said:
Tony,

Thanks for the response. I could not get this to work--it caused Word to
hang up.

Regards,
Bill Leonard

Tony Jollans said:
You should be able to do this without VBA, with a single Replace
operation:

Find what: [!^13]@:^13 --- that's left (square) bracket, exclamation
mark,
caret, one, three, right (square) bracket, at-sign, colon, caret, one,
three

Replace with: leave empty, but with the cursor in the box, press Ctrl+B

Check "Use wildcards"

Press "Replace All"

--
Enjoy,
Tony

www.WordArticles.com

Good day,

I have been chasing my tail a bit trying various methods of moving the
selection around and can't seem to get it correct. I have many
documents
that have many sections with a heading that appear like this:

Follow this process:
and/or
Begin the routing as follows:

There is no formatting to these section headings--it is just plain
text.
Most of the text that follow each section are single-line
paragraphs--just
as
the section headings are (that should make this effort easier? right?)
I
would like to loop through the paragraphs, test them for the last
character
being ":" and then bold the entire line (paragraph).

I checked the board for a similar posting but did not find one.
Thanks
to
anyone who might provide some guidance.

Regards,
Bill Leonard
Hingham, MA

.

.
 

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