determining whether any characters in range have formatting

L

Larry

I have a range that's eight characters wide. I want to know if any
characters in the range have underlining formatting. How can I do this,
other than using Find?

Larry
 
J

Jonathan West

Larry said:
I have a range that's eight characters wide. I want to know if any
characters in the range have underlining formatting. How can I do this,
other than using Find?

Larry

This will do the needful. (myRange is your predefined range)

Select Case myRange.Font.Underline
Case wdUnderlineNone
'not underlined
Case wdUndefined
'some text is underlined
Case Else
'all the text is underlined
End Select
 
H

Helmut Weber

Hi Larry,
Dim oRng As Range
Set oRng = Selection.Range
' range or selection doesn't matter
MsgBox oRng.Font.Underline
' 0 = none underlined
' 1 = all underlined in style wdUnderlineSingle
' 9999999 at least 1 character underlined in some way.
Would your entire range be doubled underlined, the result would be 3.

There are
wdUnderlineDashHeavy
wdUnderlineDashLongHeavy
wdUnderlineDotDashHeavy
wdUnderlineDotDotDashHeavy
wdUnderlineDottedHeavy
wdUnderlineNone
wdUnderlineThick
wdUnderlineWavyDouble
wdUnderlineWords
wdUnderlineDash
wdUnderlineDashLong
wdUnderlineDotDash
wdUnderlineDotDotDash
wdUnderlineDotted
wdUnderlineDouble
wdUnderlineSingle
wdUnderlineWavy
wdUnderlineWavyHeavy
 
L

Larry

This is good, but is there a single constant that works for whether some
OR all of the range is underlined?

Thanks.
Larry
 
L

Larry

Trying to get the same result whether there's some characters with
single underlining or all characters with single underlining, I tried
this:

If oRng.Font.Underline = 1 Or r.Font.Underline = 0.9999999 Then MsgBox
"Underline"

But this only gets the result if it's all underlined.

Thanks,
Larry
 
J

Jonathan West

Larry said:
This is good, but is there a single constant that works for whether some
OR all of the range is underlined?

OK, this will do

If CBool(myRange.Font.Underline) Then
'some or all the text is underlined
End If

or this, which you could have got from taking out a couple of lines form my
earlier one

Select Case myRange.Font.Underline
Case wdUnderlineNone
'not underlined
Case Else
'some or all the text is underlined
End Select
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Larry > écrivait :
In this message, < Larry > wrote:

|| Trying to get the same result whether there's some characters with
|| single underlining or all characters with single underlining, I tried
|| this:
||
|| If oRng.Font.Underline = 1 Or r.Font.Underline = 0.9999999 Then MsgBox
|| "Underline"
||
|| But this only gets the result if it's all underlined.
||


Change

0.9999999

to

9999999

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
L

Larry

Great, Jonathan. I was looking for a simple way of doing this, and here
it is. I never heard of that CBool function before.

Larry
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Larry > écrivait :
In this message, < Larry > wrote:

|| Great, Jonathan. I was looking for a simple way of doing this, and here
|| it is. I never heard of that CBool function before.
||

Think of it as Convert to BOOLean.

There are quite a few like this:
CStr
CDate
CLng
etc.

Just select CBool in your code and hit F1 to get the complete list and some
examples.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi Larry,
Trying to get the same result whether there's some characters with
single underlining or all characters with single underlining

besides what Jean-Guy mentioned,
oRng.Font.Underline can't tell you, whether some (!) characters
in the range are single (!) underlined. You'd have to check each
substring or character seperately. Only if all characters are
underlined in the same way, you get the value of the constant.
 

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