Creating a Custom Styles Group

A problem with some of the automation provided by Word 2010 is that you don’t always get the results you want. Even if you create a custom Ribbon configuration as described in the A Quick Method for Adding Custom Ribbon Elements post, you may not get the results you want without some experimentation. For example, you might want to add a full version of the Styles group as shown here to a custom Ribbon.

StylesGroup01

As described in my previous post, Office 2010 makes it easy to add tabs, groups, and existing or custom commands to the Ribbon. The standard practice would be to create a custom tab, Styles group within that tab, and then add the Quick Styles command to it as shown here.

StylesGroup02

The result isn’t going to be what you expected. The Custom tab will look something like this:

StylesGroup03

You don’t see any of the styles. To see them, you must click the down arrow, rather than simply view them as you would on the Home tab. No amount of configuration in Word is going to change this display. In order to get the right appearance, you must export your customizations as described in my previous post and modify the XML directly. After you export the customizations, you see XML for the Custom tab that looks like this:

<mso:tab id="mso_c1.F646E0" label="Custom" insertBeforeQ="mso:TabInsert">
   <mso:group id="mso_c3.F7999E" label="Styles" autoScale="true">
      <mso:gallery idQ="mso:QuickStylesGallery" showInRibbon="false" visible="true"/>
   </mso:group>
</mso:tab>

It’s important to note that the autoScale=”true” setting is correct and it’s something you’d need to add if you were creating this code by hand. However, the <mso:gallery> tag isn’t set up correctly right now. Unfortunately, VBA for Dummies currently suggests the answer, but doesn’t discuss it outright. My book, RibbonX for Dummies, provides better information in this case on page 151 when it describes the attributes for a gallery. In order to get the appearance you want, you need to change the code so it looks like this:

<mso:tab id="mso_c1.F646E0" label="Custom" insertBeforeQ="mso:TabInsert">
   <mso:group id="mso_c3.F7999E" label="Styles" autoScale="true">
      <mso:gallery idQ="mso:QuickStylesGallery" size="large" visible="true"/>
   </mso:group>
</mso:tab>

which means removing the showInRibbon=”false” attribute and adding a size=”large” attribute. When you make these two changes and import the updated XML into Word, you’ll see a new version of the Custom tab as shown here:

StylesGroup04

As you can see, the Custom tab now presents the Quick Styles Gallery as you’d expect. There are many situations where you need to modify the Ribbon customizations using similar techniques to get the appearance you want. If you have any questions, please contact me at John@JohnMuellerBooks.com.

 

Author: John

John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 99 books and over 600 articles to date. The topics range from networking to artificial intelligence and from database management to heads-down programming. Some of his current books include a Web security book, discussions of how to manage big data using data science, a Windows command -line reference, and a book that shows how to build your own custom PC. His technical editing skills have helped over more than 67 authors refine the content of their manuscripts. John has provided technical editing services to both Data Based Advisor and Coast Compute magazines. He has also contributed articles to magazines such as Software Quality Connection, DevSource, InformIT, SQL Server Professional, Visual C++ Developer, Hard Core Visual Basic, asp.netPRO, Software Test and Performance, and Visual Basic Developer. Be sure to read John’s blog at http://blog.johnmuellerbooks.com/. When John isn’t working at the computer, you can find him outside in the garden, cutting wood, or generally enjoying nature. John also likes making wine and knitting. When not occupied with anything else, he makes glycerin soap and candles, which comes in handy for gift baskets. You can reach John on the Internet at John@JohnMuellerBooks.com. John is also setting up a website at http://www.johnmuellerbooks.com/. Feel free to take a look and make suggestions on how he can improve it.