Here’s the previous parts to this:
Using Excel’s Images on Custom Ribbon Controls
In Part 2, we built the following custom group on a custom tab:
This time, we’ll replace all the happy face images with pictures from Excel’s native ribbon images. Once you know how, it’s actually relatively easy to state which image you want. You just replace the HappyFace portion of the imageMso tag with the name of the Excel control that we want to use. The first question that we’ll obviously need to settle, however, is “How do we get the name of the control?”
What you need to do is go into the Excel Options screen, (click the Office button, then Excel Options,) and click Customize. You’ll now see the list of all the items that you can add to your Quick Access Toolbar (QAT). If you’re a developer in prior versions of Excel, you’ll remember that you pretty much had to create a custom toolbar to work out what FaceID corresponded to what picture. The good news here, is that things are much easier.
Move your mouse over one of the menu items and hover it there. A screen tip will pop up, and you’ll find the MSO image name at the end of the string! A picture is shown below of the tool tip.
What I’ve done below is grab a few random imageMso’s and put them into the XML for the example we created at the end of part 2. (Reproduced above.) The group now looks like this:
The images were selected based only on the fact that I thought they looked interesting. That’s all. Remember that these images will only do what you program them too, as shown in Part 1 of this series.
The XML code to create this group is shown below. One final word of note here… the imageMso tag is again Case Sensitive! If you mess up the case, you get no image at all on your control. The ribbon does at least get created though, which is better than the case sensitivity issues that I told you about in Part 2.
- <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
- <ribbon startFromScratch="false">
- <tab id = "customTab" label="Custom Tab" insertAfterMso="TabView">
- <group id="customGroup1" label="Custom Group 1">
- <button id="BigButton1" label="I'm #1!" onAction="CallControl" size="large" imageMso="CalculateSheet" />
- <button id="Button1" label="Button 1" onAction="CallControl" imageMso="ChartTypeAllInsertDialog" />
- <button id="Button2" label="Button 2" onAction="CallControl" imageMso="SheetBackground" />
- <button id="BigButton2" label="I'm #2!" onAction="CallControl" size="large" imageMso="HangulHanjaConversion" />
- <button id="Button4" label="Special Button 1" onAction="CallControl" imageMso="InkingStart" />
- <button id="Button5" label="Special Button 2" onAction="CallControl" imageMso="GetExternalDataFromAccess" />
- <button id="Button6" label="Special Button 3" onAction="CallControl" imageMso="OutlineSettings" />