Refers to a popup which contains shortcut commands to give easy access to excel features. Excel offers its own standard context menu based on contexts. If user right clicks on a Sheet Tab the context menu will have usable shortcut commands related to sheet tab, if you click on a cell then it will have shortcuts related to cell and so on.
customUI is the base xml which needs to be customized to bring your own customized features in Excel. For more detail please refer my previous article Customize or Create your own ribbon in Excel step by step. We will continue using same file and add customization to build our own popup.
Step 1: Launch Microsoft Custom UI Editor and open “CustomAddin.xlsm“, Now add one picture image to decorate our new button added to Right Click context menu by clicking Insert Icon button as shown below:
Step 2: Create context menu xml as shown below, Point to be noticed:
- ContextMenu is part part of customUI ribbon
- ContextMenu provides contextMenus collection
- Each context menu will have a unique idMso (to know more idmso please refer this)
- Each context menu should have at least one control like button, label textbox etc.
<contextMenus> <contextMenu idMso="ContextMenuCell"> <button id="cWhat" label="Click to Know" onAction="Question_Click" image="Question" /> </contextMenu> </contextMenus>
Step 3: Generate Call back functions: click on Validate button to ensure the changes or customization you made within CustomUI xml are valid. Next you can click on Generate Callbacks button and final output should look like below:
Step 4: Copy call back generated above and open “CustomAddin.xlsm” file in Excel, Open VB Editor and insert one module then paste generated callbacks as shown below:
If you notice, i have placed a code to show message on click of Question_Click event which associated to my button which I have defined in the XML during customization.
Step 5: close VB Editor and right click on a cell (because the idMso we have used for cell context menu), you should have output like below:
Finally click on the “Click to Know” button as shown above and a message box will prompt with given message: