Excel Ribbon button icon change effect

umarpervaiz425

New Member
Joined
Nov 25, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
This is my requirement:
I have an xlsm file which has two tabs in the ribbon. The tabs are names as, GENERAL and GTH. There are two buttons inside GENERAL tab named "Inocio" and "Configuration". And there are two buttons inside GTH named as "Resumen" and "Detalldo". I want to make an add-in function for my file so that whenever I click on any of those four buttons inside the tabs, The effect should activate when you press on an icon and return to its original icon when you move to another. The effect should change the icon image to backup.png when clicked and return to its original image when you move to another icon.

Note: I am using RibbonX xml.

Here is my XML code:
XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

    <!-- Disable Share in the Ribbon of Excel 2016.   -->
    <commands>
        <command idMso="Collaborate" enabled="false" />
    </commands>
  <ribbon startFromScratch="true">

<tabs>
    <tab id="Tab1" label="GENERAL" >   
<group id="customGroup1" label="Home">
          <splitButton id="mySplitButton1" size="large">
            <button id="customButton1" image="inicio.png" label="Inicio" supertip="Presionar" onAction="Macro1"/>
            <menu id="splitMenu1" itemSize="normal">
              <!-- use itemSize = large or use normal -->
            <button id="customButton2" label="Hola"  onAction="Macro2" image="registrarse.png"  />
            </menu>
          </splitButton>
 <separator id="MySeparator1" />   
 <button id="customButton3" label="Configuracion" size="large" onAction="Macro3" image="configuracion.png" />
</group>
 </tab
    <tab id="Tab2" label="GTH" >   
<group id="customGroup5" label="Ficha Financiera">
          <splitButton id="mySplitButton2" size="large">
            <button id="customButton4" image="resumen.png" label="Resumen" supertip="Presionar" onAction="Macro4"/>
            <menu id="splitMenu2" itemSize="normal">
              <!-- use itemSize = large or use normal -->
            <button id="customButton5" label="Examinar"  onAction="Macro5" image="importar.png" />
            </menu>
          </splitButton>
 <separator id="MySeparator7" />   
 <button id="customButton6" label="Detallado" size="large" onAction="Macro6" image="detallado.png" />

 <splitButton id="mySplitButton60" size="large">

          </splitButton>
</group>

    </tab>

</tabs>

  </ribbon>
</customUI>
<!-- Macros UI -->

And here is my VBA code:

VBA Code:
Option Private Module
Option Explicit



'----------------------GENERAL--------------------------------
'-------Home-------
Sub Macro1(control As IRibbonControl)
    ThisWorkbook.Sheets("Inicio").Activate
End Sub

Sub Macro2(control As IRibbonControl)
    Call hola
End Sub

Sub Macro3(control As IRibbonControl)
    ThisWorkbook.Sheets("Configuración").Activate
End Sub

'----------------------GTH--------------------------------
'-------Ficha Financiera-------
Sub Macro4(control As IRibbonControl)
    ThisWorkbook.Sheets("Resumen").Activate
End Sub

Sub Macro5(control As IRibbonControl)
    Call Examinar
End Sub

Sub Macro6(control As IRibbonControl)
    ThisWorkbook.Sheets("Detallado").Activate
End Sub

Attached are the images which would be useful to understand my requirement:
now.png

required.png
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you want your buttons to show one of two possible icons, the easiest is to have two versions of each button in your ribbonX and use the getVisible callback to determine which of the two must be shown.
This also requires you to add the onLoad callback to your ribbonX so that your VBA project gets a pointer to the ribbon so you can call the Invalidate method of the ribbon when there is a change of status in your workbook which may cause a change in the icons. See for example this articl of mine where I mention that onLoad callback: Excel: Building an Excel add-in
 
Upvote 0
If you want your buttons to show one of two possible icons, the easiest is to have two versions of each button in your ribbonX and use the getVisible callback to determine which of the two must be shown.
This also requires you to add the onLoad callback to your ribbonX so that your VBA project gets a pointer to the ribbon so you can call the Invalidate method of the ribbon when there is a change of status in your workbook which may cause a change in the icons. See for example this articl of mine where I mention that onLoad callback: Excel: Building an Excel add-in
Thank you. Can you please provide me with the updated XML and VBA code?
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,105
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top