Underline text

A

Angie M.

Hi,

I have the following macro that will underline the first sentence of any
text formatted with a Heading 1 style. I'm trying to rewrite the macro to
accommodate legal style numbering as in:

ARTICLE I
LEASES AND RENTS

In this example "article 1" is auto numbering coming from the style and then
there's a line break (Shift+Enter). I want the macro to underline the title
of the section, in this case 'LEASES AND RENTS".

Here's what I have (thanks to this newsgroup) that works for outline
numbering:

Sub BoldHeadingArt()

Dim myPara As Paragraph
Dim rngPara As Range

For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
Set rngPara = myPara.Range.Sentences(1)
With rngPara

.Font.Bold = True
End With
End If
Next myPara
End Sub

Should I assign the range to something other than a sentence (because there
will be no period involved), I've tried everything I know and cannot make
this work. Can you help? Thanks
 
S

StevenM

To: Angie,

Sub BoldHeadingArt()
Dim rngPara As Range
For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
Set rngPara = myPara.Range
rngPara.Collapse wdCollapseStart
rngPara.Select
Selection.Move wdLine, 1
Selection.Bookmarks("\line").Select
Selection.Font.Bold = True
End If
Next myPara
End Sub

Steven Craig Miller
 
A

Angie M.

Thanks for helping me. For some reason that didn't work. In my test I had
three
examples:

ARTICLE 1 - LEASES AND RENTS

ARTICLE 1
LEASES AND RENTS

ARTICLE 1

LEASES AND RENTS

the last two had end of line marks (1 and then 2). The first sample didn't
have one at all.

On the first one it didn't work at all, no bold. On the second one it
worked but it bolded the ARTICLE 1 also and on the third one it didn't work.

Is there a way to take the original macro and change "Sentence" to "end of
line"??

Again thanks for your help.
 
S

StevenM

To: Angie,

The last macro attempted to find the line underneath the line beginning the
style and bold it. This next macro attempts to:

(a) collapse the range to the beginning to the style;
(b) move the begining to the range forward two words (presumably: Article
#), and
(c) looks for the first character beginning with A-Z.

It then bolds the remaining of that range.

Sub BoldHeadingArt()
Dim rngPara As Range
Dim rEnd As Long
Dim char As Long

For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
Set rngPara = myPara.Range
rEnd = rngPara.End
rngPara.Collapse wdCollapseStart
rngPara.Move wdWord, 2
rngPara.End = rngPara.Start + 1
char = Asc(rngPara.Text)
While (char < Asc("A") Or char > Asc("Z"))
rngPara.Start = rngPara.Start + 1
rngPara.End = rngPara.Start + 1
char = Asc(rngPara.Text)
Wend
rngPara.End = rEnd
rngPara.Font.Bold = True
End If
Next myPara
End Sub

Let me know if this works.

Steven Craig Miller
 
S

StevenM

P.S.

If you want the text underlined.

The previous macro should have:

rngPara.Font.Underline = wdUnderlineSingle

before, after, or in place of: rngPara.Font.Bold = True

Thus:

Sub BoldHeadingArt()
Dim rngPara As Range
Dim rEnd As Long
Dim char As Long

For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
Set rngPara = myPara.Range
rEnd = rngPara.End
rngPara.Collapse wdCollapseStart
rngPara.Move wdWord, 2
rngPara.End = rngPara.Start + 1
char = Asc(rngPara.Text)
While (char < Asc("A") Or char > Asc("Z"))
rngPara.Start = rngPara.Start + 1
rngPara.End = rngPara.Start + 1
char = Asc(rngPara.Text)
Wend
rngPara.End = rEnd
rngPara.Font.Bold = True
rngPara.Font.Underline = wdUnderlineSingle
End If
Next myPara
End Sub

Steven Craig Miller
 
A

Angie M.

Thanks Steven,

Actually I'm doing the same macro for underlining and bolding figuring they
would be the same except for the bold/und.

Okay I've tried the macro, it doesn't work. Sorry to be a pain. It only
works if there is a period somewhere in the descriptive text. When I have

ARTICLE 1 (Shift+Enter for end of line break)
RENTS AND LEASES OR OTHER DESCRIPTIVE TEXT

I still don't get the formatting on the descriptive text unless there is a
period, then it bolds after the period. I just want all the text in the
paragraph formatted with bold is really all I'm trying to do. Thanks again
for helping me!
 
S

StevenM

Angie,

I apologize for all this. If this next macro does not work, could you e-mail
me a mock-up document so that I will have exactly the text you'll want the
macro to work upon? After all, all my macros have been working for me, so I
can only assume that the text I'm practicing upon is not the same as your
text.

Sub BoldHeadingArt()
Dim rngPara As Range
For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = ActiveDocument.Styles(wdStyleHeading1) Then
Set rngPara = myPara.Range
rngPara.Start = rngPara.Start + 1
rngPara.Font.Underline = wdUnderlineSingle
End If
Next myPara
End Sub

This macro assumes that "article 1" is auto numbering. I failed to take that
into account in my previous attempts. I then moved the start of the range
forward one character to account for the line break. And underlined the rest
of the heading.

If this doesn't work, please send me a mock-up document, and I'll give it
another try.

Steven Craig Miller
 

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