Customizing Ribbon

I upgraded(?) from Office 2003 to Office 2013.  I have an add-in that I created a new ribbon tab for. It has one group that contains buttons that contain only a label, like I had on a command bar in Office 2003. I want to update those buttons when I open a workbook that also has XML that creates a workbook unique ribbon tab.

Here's what I did:

Start of Add-in XML :

 

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
  <ribbon> 
    <tabs>
      <tab id="MyAddIn" label="MyAdd-In" insertBeforeMso="TabHome">
  <group id="WSs" label="WS"> 
      <button id="AlignWS" label="Align WS" image="PAGE"/>
          <button id="InitArrays" label="Init. Arrays" imageMso="FileOpen" />
          <button id="Temp" label="Temp" imageMso="RefreshAll" />
          <separator id="WSSep0"/>
          <button id="AlignWSs" label="Align WSs" image="PAGES"/>
          <button id="NarW" label="Narrow/Wide" image="NarWide" />
          <button id="LftRt" label="Hz Align" onAction="wbleftright" image="LeftRight" />
          <button id="ReSizeWin" label="ReSize Win" size="large" imageMso="ZoomFitToWindow" />
        </group>

       

Workbook XML:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <ribbon>
    <tabs>
<tab id="MyAddIn" >
 <group id="WSs">
     <button id="InitArrays" onAction="HoldInitArrays" />
     <button id="Temp" onAction="Hold0ATemp" />
    <button id="AlignWS" onAction="HoldWorkBHomeWS" />
    <button id="AlignWSs" onAction="HoldWorkBHomeWSs" />
   <button id="NarW" onAction="HoldWinNarWide" />
   <button id="ReSizeWin" onAction="HoldWinSize" />
 </group >
</tab>
      <tab id="Holdings" label="Holdings" insertBeforeMso="TabHome">
        <group id="Actions" label="Actions">
   <button id="RmvObj" label="Remove Objects" onAction="HoldRmvObjects" imageMso="RecordsDeleteRecord" />
 </group >
</tab>
    </tabs>
  </ribbon>
</customUI>

       .
       .
March 25th, 2015 5:46pm

Hi,

So is your question how to add images to your ribbon tab or is your question how to add the ribbontab to your specific workbook? 

for adding the ribbontab this might help: http://mauriceausum.com/2011/06/22/customui-editor/

and for adding icons this might help: http://mauriceausum.com/2014/04/23/customui-editor-part-ii/

Maurice

Free Windows Admin Tool Kit Click here and download it now
March 25th, 2015 6:24pm

Neither. I reviewed your web pages and I've done all that.

I have an add-in containing many macros. In EXCEL 2003, I had several toolbars to handle these. 7 of those buttons on one of those toolbars were common to most of my workbooks (WB), so I wrote a macro (called by each WB at activation) to change these buttons to reference the active WB's macros. 

These buttons correspond to the first 7 buttons in my  "MyAddIn" tab XML above. I have a bunch more XML statements in the 

What I want to do is have each WB contain XML to change the Ribbon Buttons in the "MyAddIn" tab to the unique WSs macros. This is the second group of XML.

It doesn't work. Can't change the "MyAddIn" tab buttons.


March 31st, 2015 7:11pm

Neither. I reviewed your web pages and I've done all that.

I have an add-in containing many macros. In EXCEL 2003, I had several toolbars to handle these. 7 of those buttons on one of those toolbars were common to most of my workbooks (WB), so I wrote a macro (called by each WB at activation) to change these buttons to reference the active WB's macros. 

These buttons correspond to the first 7 buttons in my  "MyAddIn" tab XML above. I have a bunch more XML statements in the 

What I want to do is have each WB contain XML to change the Ribbon Buttons in the "MyAddIn" tab to the unique WSs macros. This is the second group of XML.

It doesn't work. Can't change the "MyAddIn" tab buttons.


  • Edited by DRARetired Tuesday, March 31, 2015 11:14 PM
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 11:10pm

Neither. I reviewed your web pages and I've done all that.

I have an add-in containing many macros. In EXCEL 2003, I had several toolbars to handle these. 7 of those buttons on one of those toolbars were common to most of my workbooks (WB), so I wrote a macro (called by each WB at activation) to change these buttons to reference the active WB's macros. 

These buttons correspond to the first 7 buttons in my  "MyAddIn" tab XML above. I have a bunch more XML statements in the 

What I want to do is have each WB contain XML to change the Ribbon Buttons in the "MyAddIn" tab to the unique WSs macros. This is the second group of XML.

It doesn't work. Can't change the "MyAddIn" tab buttons.


  • Edited by DRARetired Tuesday, March 31, 2015 11:14 PM
March 31st, 2015 11:10pm

When changing images during runtime (or at strartup) you can use "GetImage", perhaps you can use a similar approach for "GetOnAction". Possibly you need to create a public variable which is changed on workbook activate and use that to redefine the button "OnAction" with invalidate.

Check Ron de Bruin's page on Ribbon images (can't paste links yet) for more information and examples, or seach the web for "Ribbon GetImage".

Alternatively the "OnAction" macro can be programmed to call a different macro depending on which workbook is active, using a public variable as describe above.

I haven't tried either solution yet so it might not work, but I expect it will.


Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 5:59am

When changing images during runtime (or at strartup) you can use "GetImage", perhaps you can use a similar approach for "GetOnAction". Possibly you need to create a public variable which is changed on workbook activate and use that to redefine the button "OnAction" with invalidate.

Check Ron de Bruin's page on Ribbon images (can't paste links yet) for more information and examples, or seach the web for "Ribbon GetImage".

Alternatively the "OnAction" macro can be programmed to call a different macro depending on which workbook is active, using a public variable as describe above.

I haven't tried either solution yet so it might not work, but I expect it will.


  • Edited by AlexFolmer Wednesday, April 01, 2015 9:58 AM
April 1st, 2015 9:57am

I think I'm misstating the problem.

I have a custom tab on the ribbon in Excel 2013. The xml for it is in an add-in that loads at Excel initialization.

What I want to do is, when I open a workbook, change the "onAction" in a few  buttons on the custom tab using the XML in opening workbook.

Is there some VBA code that can do it?

This for my use only.

Thanks to anyone who can help.

Don


Free Windows Admin Tool Kit Click here and download it now
April 4th, 2015 2:26pm

I think I'm misstating the problem.

I have a custom tab on the ribbon in Excel 2013. The xml for it is in an add-in that loads at Excel initialization.

What I want to do is, when I open a workbook, change the "onAction" in a few  buttons on the custom tab using the XML in opening workbook.

Is there some VBA code that can do it?

This for my use only.

Thanks to anyone who can help.

Don


  • Edited by DRARetired Saturday, April 04, 2015 7:41 PM
April 4th, 2015 6:25pm

Have just tried a few options and the found a solution.

In each workbook you are using, make sure the macro to call for each button has the same name. Then in the main xml create the buttons as normal with a fixed OnAction. In the OnAction macro write the following:

Sub callMacro()
Dim MacroName As String
MacroName = "'" & ActiveWorkbook.Name & "'!buttoncall"
Application.Run (MacroName)
End Sub

This calls the macro "buttoncall" from the active workbook, i.e. the workbook which at the moment of call has focus. In each workbook write the workbook specific code in the "buttoncall" macro.

This is a very flexible solution and will run the correct macro indepenent of how many workbooks are open.

You might want to consider creating and error routine to prevent errors if a workbook is open without the macro.



Free Windows Admin Tool Kit Click here and download it now
April 7th, 2015 5:16am

Thanks, it worked.

One caution is do NOT give the same name to the add-in macro as the workbook macro.

Here's an example of what worked:

Add-in

Sub WBNarWide(Optional control As IRibbonControl)
Dim MacroName As String
On Error Resume Next
MacroName = "'" & ActiveWorkbook.Name & "'!WinNarWide"
Application.Run (MacroName)
On Error GoTo 0
End Sub

Workbook:


Sub WinNarWide()
HoldWinNarWide
End Sub

April 7th, 2015 3:24pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics