Prev: Print First Two pages in First Page Tray & remang. in other pages
Next: Missing red squigglies when automating WORD.
From: gbonamie on 4 Jun 2010 11:50 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?
From: Doug Robbins - Word MVP on 4 Jun 2010 17:50 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 "gbonamie" <gbonamie(a)gmail.com> wrote in message news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62(a)g7g2000yqj.googlegroups.com... > 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?
From: Greg Maxey on 4 Jun 2010 21:23 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. Doug Robbins - Word MVP wrote: > I think that Greg Maxey may have something on that on his website > http://gregmaxey.mvps.org/word_tips.htm > > > "gbonamie" <gbonamie(a)gmail.com> wrote in message > news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62(a)g7g2000yqj.googlegroups.com... >> 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?
From: gbonamie on 6 Jun 2010 06:23
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 On Jun 5, 3:23 am, "Greg Maxey" <gma...(a)mIKEvICTORpAPAsIERRA.oSCARrOMEOgOLF> wrote: > 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. > > Doug Robbins - Word MVP wrote: > > > > > I think that Greg Maxey may have something on that on his website > >http://gregmaxey.mvps.org/word_tips.htm > > > "gbonamie" <gbona...(a)gmail.com> wrote in message > >news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62(a)g7g2000yqj.googlegroups.com... > >> 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? |