Ribbon - Togglebutton for custom style

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?
 
D

Doug Robbins - Word MVP

I think that Greg Maxey may have something on that on his website
http://gregmaxey.mvps.org/word_tips.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

Greg Maxey

I have a toogle button in the demo shown here:

http://gregmaxey.mvps.org/Proofreader_Marks_AddIn.htm

Unfortunately unlike built-in toggle button controls (e.g. Bold) the custom togglebuttons do not monitor the state of text in the document.

I mean it it possible to have a toogle button that that changes the applied style from one style to another, but that toggle button will not physically monitor and state of selected text.
 
G

gbonamie

Thanks a lot for the links -before I came here I had already spent
some time on your site. But if I understand you correctly, then what I
am asking for is simply not possible -what a pity!

Thanks!

Geert
 

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