3
votes

I've search for this and only been able to find the reverse (i.e. add a custom function to an existing ribbon tab/group).

We have a custom ribbon that we want to add some built-in functions to, e.g. we have a few custom number format buttons and beside those, I want to add the regular built-in increase/decrease decimal places buttons so that user doesn't have to return to the Home tab to change decimal places.

How do I add these built-in buttons to my custom tab/group?

I'm on VS 2017, and so far, my method has been using the visual designer to add controls and then clicking through the 'view code' option to code the functionality.

1

1 Answers

3
votes

You can't add a built-in control in the Ribbon Designer. Best you can do is to call the Excel functionality you want to use from within the event handler for your custom button.

If you export the Ribbon to XML you can use native Office controls in the Ribbon XML definition by assigning the Control ID value to a control's idMso attribute. Note that the control type must be the same type (you can't use a dropdown instead of a toggle button, for example).

Here's minimal Ribbon XML that shows the elements for the two buttons you ask about:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="My Group">
          <button idMso ="DecimalsIncrease"/>
          <button idMso ="DecimalsDecrease"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

Depending on the version of Office you're targeting, you can download files of control IDs for the various Office applications. The download is an exe file that unzips to 30+ Excel files listing all (well, most of) the Control IDs. Here are the links to downloads for the current versions of Office:

Office 2010

Office 2013

Office 2016

Office 2007