Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Read the Status of the Built-In Italic Toggle Button?

Status
Not open for further replies.

DrGreg1408

Technical User
Feb 8, 2008
30
US
I apologize beforehand if there is an obvious answer to this question. I have searched and not found that answer, but that doesn't mean it's not right there staring me in the face.

Does anyone know how to use VBA to read the state of the Italic built-in toggle button, i.e., whether it is depressed or not?

The following does not work:

Commandbars("Formatting").Controls("&Italic").State

That always returns a zero no matter which state the button is in.

What I want to do is intercept the button so that, instead of applying the italic formatting, it will apply the Emphasis character style. And vice versa; if the button is currently depressed, then when the user clicks it (unselects it), I want the Emphasis character formatting removed. But to do this, I need to be able to read the current status of the button.

gsw
 



Hi,

It's not the status of the button. It is the Font.tttt property of the selected text, be it BOLD or ITALIC, etc.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
mintjulep,
Your solution gives the same results as what I had done (without the Item key word). It always outputs to zero.

SkipVought,
Your solution works! So, somehow that button automatically reflects the Italic property of the current selection. Here is my solution:

Public Sub Italic
With Selection
If .Font.Italic Then
.ClearFormatting
Else
.Style = ActiveDocument.Styles("Emphasis")
End If
End With
End Sub
 
mintjulep,

That sounds like the way it should work. Otherwise, why have a state property in the first place? Yet, mine always renders as 0. Maybe it has to do with the version. I'm running Office 2003.

gsw

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top