Context Menu or Right Click Popup creation in Excel with example

Context Menu or Right Click Popup creation in Excel with example

Context Menu

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

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:

  1. ContextMenu is part part of customUI ribbon
  2. ContextMenu provides contextMenus collection
  3. Each context menu will have a unique idMso (to know more idmso please refer this)
  4. Each context menu should have at least one control like button, label textbox etc.

XML

<contextMenus>
			<contextMenu idMso="ContextMenuCell">
				<button id="cWhat" label="Click to Know" onAction="Question_Click" image="Question" />
			</contextMenu>
	</contextMenus>

Final customization

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:

Leave a Reply

Your email address will not be published. Required fields are marked *