G
gbonamie
Hi,
I have developed a Word PhD template for our faculty which adds a new
tab in the Ribbon. That tab has, among others, a set of buttons that
apply custom styles to the active selection. Until now I have used
simple buttons that fire a macro which in its turn applies the style.
Now, however, I am tweaking the details and would rather replace these
buttons by togglebuttons -problem is: I cannot get it to work and find
myself struggling with the callbacks. In my ribbon xml I have for
instance the following togglebutton: <togglebutton id="tbExample"
image="Example" onAction="Example_Click" />.
In my Callbacks module I then have the following routine:
Sub Example_Click(control As IRibbonControl, pressed As Boolean)
If pressed Then
Selection.Style = ActiveDocument.Styles("Example")
Else:
'What goes here?
End If
End Sub
As you can see, I haven't figured out that much yet
The problem is:
no matter where the user places the cursor in the text, it should be
that below the surface Word is scanning whether or not that current
selection has the style "Example"; if so, then this togglebutton
should be highlighted. If a user has a selection which already has the
style "Example" then clicking the togglebutton should return the
selection to its original style.
I am not a programmer and I just don't know how to translate that into
VBA. I have read quite a few documents & websites on ribbon
customization, but I can't seem to tweak what I read so that it works
in my situation. Is there anyone who can point me in the right
direction?
I have developed a Word PhD template for our faculty which adds a new
tab in the Ribbon. That tab has, among others, a set of buttons that
apply custom styles to the active selection. Until now I have used
simple buttons that fire a macro which in its turn applies the style.
Now, however, I am tweaking the details and would rather replace these
buttons by togglebuttons -problem is: I cannot get it to work and find
myself struggling with the callbacks. In my ribbon xml I have for
instance the following togglebutton: <togglebutton id="tbExample"
image="Example" onAction="Example_Click" />.
In my Callbacks module I then have the following routine:
Sub Example_Click(control As IRibbonControl, pressed As Boolean)
If pressed Then
Selection.Style = ActiveDocument.Styles("Example")
Else:
'What goes here?
End If
End Sub
As you can see, I haven't figured out that much yet
no matter where the user places the cursor in the text, it should be
that below the surface Word is scanning whether or not that current
selection has the style "Example"; if so, then this togglebutton
should be highlighted. If a user has a selection which already has the
style "Example" then clicking the togglebutton should return the
selection to its original style.
I am not a programmer and I just don't know how to translate that into
VBA. I have read quite a few documents & websites on ribbon
customization, but I can't seem to tweak what I read so that it works
in my situation. Is there anyone who can point me in the right
direction?