Hi All,
In a nut shell, I have multiple buttons in a custom ribbon (with multiple custom icons for each button) and would like the icon to be different depending on a cell value (different cell controlling each button).
Therefore, I have used a callback to set the image to load for each button.
However, (issues 1) I cant seem to get the image to load (VBA states "compile error: object required", see example VBA code below for btn1, same for btn2 just change 1 to 2). The "image" name line (after "Set") is exactly how I would write the xml code if the image was fixed (between image and the final ").
The full XML code for the example workbook is below (hide editing group to make space):Sub CallBackBtn1Img(control As IRibbonControl, ByRef image) Select Case control.ID Case "btn1" Select Case btn1enabled Case True: Set image = "_x0031_enabled" Case False: Set image = "_x0031_off" End Select End Select End Sub
Issue 2<?xml version="1.0" encoding="utf-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_OnLoad"> <ribbon> <tabs> <tab idMso="TabHome"> <group idMso="GroupEditingExcel" visible="false"/> <group id="Buttons" label="Test Buttons"> <button id="btn1" label="Test Button 1" getImage="CallBackBtn1Img"/> <button id="btn2" label="Test Button 2" getImage="CallBackBtn2Img"/> </group> </tab> </tabs> </ribbon> </customUI>
In the example workbook attached, I am changing the state (case) by pressing a button on the worksheet (instead of a cell value just to make it easier to do), but I cant work out how to get the ribbon to refresh (comes up with argument not options). Code for changing state of btn1 below (included line numbers to help me pin down problem, but it didn't help):
I have scoured all of the code I could find from example workbooks by Ron de Bruin and Gregory Maxey, but just cant seem to work it out either of these problems.Sub ChangeBtn1(control As IRibbonControl) On Error GoTo ErrorHandler 10 If btn1enabled = True Then 20 btn1enabled = False 30 Else 40 btn1enabled = True 50 End If 60 RefreshRibbon ("btn1") Exit Sub ErrorHandler: Debug.Print "Error # " & Str(Err.Number) & " was generated by line number: " & Erl End Sub
Ideally, I would like to load the images from within the file itself (without un-zipping the images into another folder).
The example workbook attached shows what I have at the moment.
Please can someone help.
Thank you in advance
Aman



