# How to add custom button to the right click/context menu in Excel?

Step 1

Open an excel sheet and Press Alt and F11 key (Alt+F11) to open Microsoft Visual Basic for Application windows. See the below given image.

Step 2

After that, select Insert > Module from the menu bar to bring up the popup Module window. See the below given image.

Step 3

After opening the Module Window, then type the following VBA code in it.

Sub AddItemToContextMenu()
Dim cmdNew As CommandBarButton

With cmdNew
.Caption = "My Button"
.OnAction = "MyButton"
.BeginGroup = True
End With
End Sub


After adding the VBA code, Press F5 or click on Run tab. Then Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.

The only thing you need to do is update is .Caption property to any menu text you want to use, and Adjust the .OnAction property so that it points to the desired command or macro to be executed.

You can use the following macro if at a later time you decide that you no longer desire the menu option.

Sub RemoveContextMenuItem()
On Error Resume Next
CommandBars("cell").Controls("My Button").Delete
End Sub


To make advantage of this, replace the text that says "My Button" with the text that you used in .Caption property of the macro written above. In this particular macro, the On Error statement is present simply in case the designated macro item had not been included in the earlier additions.

Now select any cell and right click there You will see “My Button” button added to the list.