G
Greg Maxey
I learned something interesting today about the .Bold attribute (is that the
right term?)
I have some text in quotations "BOLDtext unboldtext" "Boldtext"
"Unboldtext"
I have a wildcard seach to look for text within quotation marks. I then
strip the quotaions marks and evaluate the remaining range. "IF" the range
(the whole range)is BOLD I want to do something.
Using this macro to illustrate, I learned the the statement:
If myrange.Font.Bold Then
Doesn't necessarily mean all the font in the range is bold. It appears to
mean that part of it or that not of it is not bolded.
Type "BOLD unbold" in a document with the quotation marks and BOLD word
bolded and run this illustration.
Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.StoryRanges(wdMainTextStory)
With myRange.Find
'Find bold text in quotes
.Text = """*"""
.MatchWildcards = True
.Execute
'Strip quotation marks
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
myRange.Select 'You can see what is selected
If myRange.Font.Bold Then
MsgBox "Well not really true as part of the font isn't bold"
MsgBox myRange.Font.Bold 'Returns 999999 & " A -1 means really true"
End If
If myRange.Font.Bold <> -1 Then 'Or not true
MsgBox "Test Sat"
End If
End With
End Sub
So my lesson learned is that I can't take it for granted that statements
like
If whatever (thinking that means If whatever is true) Then
do something.
right term?)
I have some text in quotations "BOLDtext unboldtext" "Boldtext"
"Unboldtext"
I have a wildcard seach to look for text within quotation marks. I then
strip the quotaions marks and evaluate the remaining range. "IF" the range
(the whole range)is BOLD I want to do something.
Using this macro to illustrate, I learned the the statement:
If myrange.Font.Bold Then
Doesn't necessarily mean all the font in the range is bold. It appears to
mean that part of it or that not of it is not bolded.
Type "BOLD unbold" in a document with the quotation marks and BOLD word
bolded and run this illustration.
Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.StoryRanges(wdMainTextStory)
With myRange.Find
'Find bold text in quotes
.Text = """*"""
.MatchWildcards = True
.Execute
'Strip quotation marks
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
myRange.Select 'You can see what is selected
If myRange.Font.Bold Then
MsgBox "Well not really true as part of the font isn't bold"
MsgBox myRange.Font.Bold 'Returns 999999 & " A -1 means really true"
End If
If myRange.Font.Bold <> -1 Then 'Or not true
MsgBox "Test Sat"
End If
End With
End Sub
So my lesson learned is that I can't take it for granted that statements
like
If whatever (thinking that means If whatever is true) Then
do something.