ToggleButton on Ribbon - change ribbon icon

BenW71

New Member
Joined
Apr 19, 2018
Messages
26
I have an excel addin that has a bunch of buttons and functions in it. Part of this is a togglebutton on the ribbon that i would like to use to change a pivot table to use dollars versus hours as the displayed values...

I would like the items to change between a bank icon and a clock icon.

I have the ribbonUI defined as below (i only have the toggle button here, there's a lot more):

VBA Code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" >
    <ribbon startFromScratch="false">
        <tabs>
            <tab id="customTab" label="Checkbox Tab" insertBeforeMso="TabHome" getVisible="RibbonVisible">
                <group id="GroupAdditionalButtons" label="Filter Functions">
                    <toggleButton id="buttonToggleHoursDollars" getImage="getImageHoursDollars" onAction="ToggleHoursDollars"
                            getScreentip="GetScreentipHoursDollars" getSupertip="getSupertipHoursDollars" size="large" />
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

I have loaded the images into the ribbon as far as i can tell...
1703971730360.png
(note: i changed the xml to use image="bank" and it shows fine, but i can't toggle it that way- i just did this to see if it was loaded)

I then am using a named range in the worksheet within the addin and the getImageHoursDollars is:
VBA Code:
Sub getImageHoursDollars(control As IRibbonControl, ByRef returnedVal)
Dim PivotDataWS As Worksheet, R As Range
    
    Set PivotDataWS = ThisWorkbook.Worksheets("PivotFilters")
    Set R = f_CellRef("HoursOrDollars", PivotDataWS)
    
    If R = "Hours" Then
        returnedVal = "clock"
    Else
        R = "bank"
    End If
    
MsgBox "Setting image to display " & R

End Sub

The image however never displays (though "Setting image to display bank" or "...hours" does work fine...

ALSO, the caption and supertip never display either...
VBA Code:
'Callback for buttonToggleHoursDollars getScreentip
Sub GetScreentipHoursDollars(control As IRibbonControl, ByRef returnedVal)
Dim PivotDataWS As Worksheet, R As Range
    
    Set PivotDataWS = ThisWorkbook.Worksheets("PivotFilters")
    Set R = f_CellRef("HoursOrDollars", PivotDataWS)
    
    If R = "Hours" Then
        R = "Display in dollars"
    Else
        R = "Display in hours"
    End If
End Sub

1703972268521.png
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I would like to use the toggle button functionality for this, but poking around other places i saw someone with the same issue just uses two different normal buttons and uses getvisible to swap between the two. That seems viable so i'll do that.
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,046
Members
449,092
Latest member
ikke

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