Ribbon - Togglebutton for custom style

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?
0
gbonamie
6/4/2010 3:50:43 PM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
3962 Views

Similar Articles

[PageSpeed] 19

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@gmail.com> wrote in message 
news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62@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? 

0
Doug
6/4/2010 9:50:02 PM
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. =20

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
>=20
>=20
> "gbonamie" <gbonamie@gmail.com> wrote in message
> =
news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62@g7g2000yqj.googlegroups.com...
>> Hi,
>>=20
>> 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=3D"tbExample" image=3D"Example" onAction=3D"Example_Click" />.
>>=20
>> In my Callbacks module I then have the following routine:
>> Sub Example_Click(control As IRibbonControl, pressed As Boolean)
>>=20
>> If pressed Then
>>    Selection.Style =3D ActiveDocument.Styles("Example")
>> Else:
>>    'What goes here?
>>=20
>> End If
>> End Sub
>>=20
>> 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?
0
Greg
6/5/2010 1:23:13 AM
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=A0am, "Greg Maxey"
<gma...@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 cust=
om 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 appli=
ed style from one style to another, but that toggle button will not physica=
lly monitor and state of selected text. =A0
>
> 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...@gmail.com> wrote in message
> >news:3136bb11-d18e-4fa9-8fbb-c86b58b31c62@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=3D"tbExample" image=3D"Example" onAction=3D"Example_Click" />.
>
> >> In my Callbacks module I then have the following routine:
> >> Sub Example_Click(control As IRibbonControl, pressed As Boolean)
>
> >> If pressed Then
> >> =A0 =A0Selection.Style =3D ActiveDocument.Styles("Example")
> >> Else:
> >> =A0 =A0'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?

0
gbonamie
6/6/2010 10:23:08 AM
Reply:

Similar Artilces:

Adding argument description to custom functions
Hi does anyone knows how to add description to custom functions' arguments so that a description of each argument can be displayed in the formula palette? thanks ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ VBA functions don't support text descriptions in the Function wizard. You can look at the information Laurent Longre has posted on his site about this: http://longre.free.fr/english/func_cats.htm Newer addin that supports this: http://longre.free.fr...

2-Page Mail Merge Custom Document
I'm trying to print a 4-up postcard (1/2 page on 11x17 paper) that is has a mail merge on one page and grahics on the other. I get the standard "Publisher cannot merge with this number of pages." error message. Does anyone know of a work around? Other than their FAQ suggestion to use a pre-defined page layout. I need to use "Custom" so that the 8.5" x 5.5" postcard will print 4-up on an 11" x 17" sheet of paper. HELP?!?!?! I tried what you suggested. I still get the same error message. It tells me I can't have a 2-page, custom-sized do...

APA STYLE
I HAVE BEEN USEING THE APA STYLE WITH MY PC AND WAS HAPPY TO SEE IT ON MY NEW MAC BUT I HAVE NOT FOUND THAT IT IS A TRUE APA STYLE. MAYBE I AM MISSING SOMETHING IS THIER ANY INFORMATION YOU CAN GIVE ME ON FORMAT, AND REFERENCES USE WITH THIS PROGRAM? IT WOULD BE NICE TO USE THE NEW COMPUTER TO WRITE MY PAPERS.<br> MAHALO, CONNIE Hi Connie, Typing in all caps is interpreted on the web as YELLING, and so it's a bit rude. It's also quite difficult to read. What version of Word are you using? Do you mean the citation manager, that generates citations for you, doesn't seem t...

How to set the status of customize entity automatically??
Hi, Last time i create an entity to capture expense cost associated with opportunity. When the opportunity is being closed for either win/lost, i wish that the expense attached to the opportunity is being updated automatically. I have tried to accomodate this by using workflow. However till now i have not found the way. the condition that i used when expense entity is being created, check the opportunity status then update the status to inactive. However i did not see the status of expense being updated. Is there a workaround beside using workflow? How to do it? Carrie Carrie, The...

Modifying Window Style From Handle
Hey, I have a handle to a window in a different process, and I want to hide or change the border of one of its child windows. How can this be achieved? I figure its probably has to do with using the WM_STYLECHANGING and WM_STYLECHANGED window messages but not exactly sure how. Any help would be appreciated! Thanks in advance, --sternr You can use SetWindowLong with GWL_STYLE index. AliR. "sternr" <SternR@gmail.com> wrote in message news:bba53d90-32c8-43b5-be0d-6bb86bfc7534@k13g2000hse.googlegroups.com... > Hey, > I have a handle to a window in a different proce...

Style Holdover from Word
Hi, I am using Word's Outline View and the "Send to Microsoft Office PowerPoint" function (added from the "Items not on the ribbon" in Word) to create slides from my outline points. Everything comes in just fine, but when I go to change the style of my slides, it changes only the backgrounds, not the text formatting. In other words, my text comes in blue and stays blue no matter what i do - can't change the font automagically, either. I'm not sure whether to post this to the Word group or the Powerpoint group, so I apologize if this is in the wrong...

Global Customer Updating E-mail Address
I am trying to update customer email addresses through HQ but the e-mail address in our Global Customer Properties is greyed out. I have complete administrator rights, full access to all information except the customer's e-mail. Yes I am in maintenance mode, yes I have check field level security. What am I missing? Any suggestions would be helpful. -- Many thanks Jack Master Weird. Running version 2.0.0123, email field is editable, no problem. Logged in as the administrator, in maintenance mode. What version are you running? Are you in a domain? "Jack of All trades, Maste...

Apply one custom view to all folders in Outlook 2003?
Hello, I've recently installed Outlook 2003 and I'm having trouble getting rid of the "Show in Groups" option on all the folders. Any help would be greatly appretiated. Thank you, Brad ...

Importing Customer Data from DataEase
Hi I am converting an inventory system from a dos-based database called DataEase to Access. In the DataEase system a 4 digit customer number (called a numeric string in DataEase) uniquely identifies each customer in the Customers table. This number is used as the basis for a relationship between the Customers table and the Invoices table. The Customers table has approx 1000 records and the Invoices table has approx 9000 records. I need to import the data from the Dataease system to Access but I need help on the best way to proceed. The customer number field in the Customers table (in Dat...

Customer Deposits #2
Is there a report that can be used to reconcile customer deposits? I've created a smartlist that pulls the Deposits Received, but I was wondering if there was a formal report. ...

Advanced Find for Customer Address does not show Parent id
I need to get a list of Customer Addresses with some criteria in Advanced find and I would like to see the Contact they are related to. I have selected the column parentid to be shown in the grid, but it is blank for all the rows. It seems to be a problem of rights but I am logged in as Administrator. Can anyone help me? Thanks, Anna ...

CRM customization 07-24-06
I am trying to build a dataset using C# on fetching accounts. I need to define a primary key on the dataset, so I can search on the basis of the primary key. When I use the fetch, I get this violation. When I do a direct call to sql server, I am able to acheive my result. When I use the fetch I get the following error, I have attached part of the code after the error. I was under the impression the dataset is disconnected from CRM server. Any insights will be helpful <resultset morerecords='0' paging-cookie='$1$$account$accountid$1$0$38${AE8FE5C5 -0419-DB11-B5EB-001143EFFB85}...

How to change the default paragraph style
in a new message? The format is HTML and the style is paragraph. We want it to be normal! Word is not the editor. Can change it one time but when we do another new message it changes back to paragraph! ...

ROYAL STYLE #10 BELTS (2)PK
List Price:$3.95 Image: http://bestdeallocator.info/image.php?id=B0015OMZLM Best price found: http://bestdeallocator.info/index.php?id=B0015OMZLM ROYAL STYLE #10 BELTS (2)PK ...

Viewing Payment for a Customer Invoice
Is there an easy way to view a payment made against an already posted customer invoice? Currently deposits are posted in batches using Cash Receipts. Is there a way to drill down to the payment information when only the invoice number is known? If you know the invoice number, you can go to Inquiry >> Sales >> Transactions by Document No and enter the invoice number. Click redisplay. Highlight the row in the grid and click the Amount Remaining hyperlink to see the payments applied to the invoice. -- Charles Allen, MVP "Debbie" wrote: > Is there an easy w...

XL2007: Ribbon commands greyed-out after playing a macro
Hi there, In XL2007, the ribbon commands are greyed-out after playing a macro, at least this has happened on my computer time after time (Vista Home Prof Dutch). Any thoughts on this? Greetings, Peter Correction: Already greyed out on opening the file, which occurs as Read-only automatically. Propably because it is an .xlsm file. For this, refer to my other question in this group: "XL2007: Read-only automatically applies to ..xlsm files" "Peter" <scotsman@xs4all.nl> schreef in bericht news:46686078$0$7048$e4fe514c@dreader28.news.xs4all.nl... > Hi ther...

Customizing the associated view using plug-in
Is there any supported method or technique in customizing the associated view of an entity? for example, when you selected an Opportunity record and selected the Activities in the navigation pane, you can select or choose from the filter dropdown list. Can we change that items? --- avast! Antivirus: Outbound message clean. Virus Database (VPS): 090503-0, 05/03/2009 Tested on: 5/4/2009 3:20:35 PM avast! - copyright (c) 1988-2009 ALWIL Software. http://www.avast.com There is no supported method to change any of the (associated) views using code (.net or javascript). -- Patrick Ver...

problems with publising customization
hi, can someone help me with this? if i only have one server, is necesary to publish the customization? when i try to publish i have this problem when start download xsl templates: "publish completed with errors. please see event log for details. error, failed to download XSL template files from web server" thanks Yes, you need to publish your customizations. With this error, I would first take a look to make sure all the CRM services are started and that the account you're using to launch Deployment Manager is the same account you installed CRM with and has System Admi...

Customer's Acct Receivable REport
Last week a customer returned an item. The customer maintains a charge account with us. So instead of refunding it as cash, I used the tender type that we use for charges. I expected the $3 credit to be deducted from their account. It was and it wasn't. I use the "Customer Report: Accounts Receivable DETAIL" to track these charges. For some reason, it would not display the $3 credit. I tried adjusting the filters, but could not get any report that showed current balances AND the negitive ($3) transaction. According to this report, my customer owed $3 MORE then th...

Styles
I use sytles for two types of headings and a bullet style. Sometimes (I can't identify any pattern) when I open a file, the styles settings have changed for one of the headings (an extra 6 point spacing after each paragraph) and for the bullet (an extra 6 point spacing after each paragraph and the justification changing from left to justified). Does anyone know why this happens? It is annoying as it happens about 1 in 5 times and I must go through and reset the styles. Jay Garland ...

customizing the view
Is it possible to remove the menu from a view window? Let me clarify: I am presently using a single document interface. Can I alter the frame's window to the point of removing the menu? "Steve Russell" <srussell@innernet.net> wrote in message news:0a6401c3d6ad$fc9d2830$a301280a@phx.gbl... > Let me clarify: I am presently using a single document > interface. Can I alter the frame's window to the point of > removing the menu? See if the instructions in this kb article have any merit... http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B131368 ...

How to change font style for highlighting using ITextDocument
Hello, Using the Rich Edit Control I am able to change the font style at will for text ranges but this causes the document to be flagged as modified which is not what I want, how can I modify the font but not effect the modified flat? Eli >Using the Rich Edit Control I am able to change the font style at will for >text ranges but this causes the document to be flagged as modified which is >not what I want, how can I modify the font but not effect the modified flat? Eli, Have you considered calling CRichEditCtrl::SetModify to clear the control's modified flag? Dave -- MVP VC...

New Style Button
Is there any way to create a new style button, similar to the Currency and percent Style Buttons? I have created a date style that I yse regularly and would like a 1 click access to it. I know that I can drag tie Format|Style drop list on to my toolbar using Tools|Customise and have done that, but that is still a two click access to the style. I guess that I'm just lazy :-) unlikeKansas First you would have to write a macro that applied the style to your current selection: Sub ApplyMyStyle() Selection.Style = "MyStyle" 'sub your style's name End Sub and p...

Including custom layouts with an add-in
Hello all, Question: How do I distribute custom layouts with an add-in I've created? Details: I am writing an add-in which retrieves data from a database and creates a slide or slides based on the results. The add-in is pretty much complete and seems to work fine. As part of this process I created several custom layouts and added them to the default slide master. Now when I try to test the add-in machines other than the one it was developed on I embarrassingly notice the layouts are not available. My assumption was if the macro-enabled powerpoint I used to generate the...

Customize Outlook Today #49
My Customize Outlook Today will not work. I have tried everything. i want to change my settings, but I can't due to this problem. Any suggestions? oh41000@charter.net <oh41000@charter.net> wrote: > My Customize Outlook Today will not work. I have tried > everything. Except Google or support.microsoft.com. See this: http://support.microsoft.com/?id=820575 -- Brian Tillman ...