In this example, a button is created in the Excel right-click menu, the title of the button is dynamically obtained using getLabel, and the icon is dynamically obtained using getImage.
customXML code:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OL"> <contextMenus> <contextMenu idMso="ContextMenuCell"> <button id="Button1" getLabel="GL" getImage="GI" insertBeforeMso="Cut"/> </contextMenu> </contextMenus> </customUI>
VBA callback code in workbook:
Public R As IRibbonUI Public Sub OL(ribbon As Office.IRibbonUI) Set R = ribbon End Sub Public Sub GL(control As Office.IRibbonControl, ByRef label) label = Time End Sub Public Sub GI(control As Office.IRibbonControl, ByRef image) Dim rnd As Integer rnd = Application.WorksheetFunction.RandBetween(65, 90) image = Chr(rnd) End Sub
Effect demonstration:
If you want to learn more Office development skills, join the group and contact the group owner! Almost full!