J
Jon Borel
Hello,
I have a Word 2003 event handler that checks to see if the current
selection/cursor position is in text of the style "Bold Word." If so, the
event handler shows my "Bold Word" toolbar button as depressed. Note: The
"Bold Word" toolbar button runs a macro that toggles the bold style on & off.
' Class Module Private Sub below:
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
CommandBars("myToolbar").Controls(1).State = msoButtonDown
Else
CommandBars("myToolbar").Controls(1).State = msoButtonUp
End If
It was working fine, until I selected a non-text object (say a text box or
image); it throws an error (e.g., "Object variable or With block variable not
set" or "Method not available because the object refers to a drawing
object"). So I tried to trap/filter any selection that wasn't text by
nesting the IF/THEN shown above in another IF/THEN:
If Selection.Type = wdSelectionNormal Then
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
CommandBars("TCO Tools").Controls(1).State = msoButtonDown
Else
CommandBars("TCO Tools").Controls(1).State = msoButtonUp
End If
End If
This is working better (no errors) but now, because of the
"wdSelectionNormal" statement, I have to actually Select text (not just click
in a word). In other words, if I simply click in a word, the nested If/Then
doesn't fire, and nothing happens to my "Bold Word" toolbar button until I
select (hightlight) one or more characters.
When I click in (or select) a word, I want the macro to highlight my button
just like Word highlights the Bold button when you click/select a word that
is bold, and dims the bold button when you click/select non-bold text. (You
don't have to actually select/highlight text, just click in it.)
Thanks,
Jon
I have a Word 2003 event handler that checks to see if the current
selection/cursor position is in text of the style "Bold Word." If so, the
event handler shows my "Bold Word" toolbar button as depressed. Note: The
"Bold Word" toolbar button runs a macro that toggles the bold style on & off.
' Class Module Private Sub below:
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
CommandBars("myToolbar").Controls(1).State = msoButtonDown
Else
CommandBars("myToolbar").Controls(1).State = msoButtonUp
End If
It was working fine, until I selected a non-text object (say a text box or
image); it throws an error (e.g., "Object variable or With block variable not
set" or "Method not available because the object refers to a drawing
object"). So I tried to trap/filter any selection that wasn't text by
nesting the IF/THEN shown above in another IF/THEN:
If Selection.Type = wdSelectionNormal Then
If Selection.Style = ActiveDocument.Styles("Bold Word") Then
CommandBars("TCO Tools").Controls(1).State = msoButtonDown
Else
CommandBars("TCO Tools").Controls(1).State = msoButtonUp
End If
End If
This is working better (no errors) but now, because of the
"wdSelectionNormal" statement, I have to actually Select text (not just click
in a word). In other words, if I simply click in a word, the nested If/Then
doesn't fire, and nothing happens to my "Bold Word" toolbar button until I
select (hightlight) one or more characters.
When I click in (or select) a word, I want the macro to highlight my button
just like Word highlights the Bold button when you click/select a word that
is bold, and dims the bold button when you click/select non-bold text. (You
don't have to actually select/highlight text, just click in it.)
Thanks,
Jon