Customizing Excel's right click menus
The following code demonstrates how to change the right click menu for an Excel Worksheet and Chart. To test this run the code below and go to a worksheet or a chart and right click it.
To restore to default menus, click on (Reset Menus)
'Alters the right click menu in a worksheet
Sub AlterWorkSheetPopup()
Dim oCtrl As Object
With Application.CommandBars("Cell")
'Clear the existing menus
For Each oCtrl In .Controls
oCtrl.Delete
Next
'Add a new menu
With .Controls.Add(msoControlButton)
.Caption = "Reset menus"
.OnAction = "Test"
End With
End With
End Sub
'Alters the right click menu in a chart
Sub AlterWorkChartPopup()
Dim oCtrl As Object
With Application.CommandBars("Plot Area")
'Clear the existing menus
For Each oCtrl In .Controls
oCtrl.Delete
Next
'Add a new menu
With .Controls.Add(msoControlButton)
.Caption = "Reset Menus"
.OnAction = "Test"
End With
End With
End Sub
' Routine will be called by the new menu items, to reset menus to default
Sub Test()
' Reset the menus
Application.CommandBars("Cell").Reset
Application.CommandBars("Plot Area").Reset
MsgBox "Reset menus to default succeeded!"
End Sub
Sub AlterWorkSheetPopup()
Dim oCtrl As Object
With Application.CommandBars("Cell")
'Clear the existing menus
For Each oCtrl In .Controls
oCtrl.Delete
Next
'Add a new menu
With .Controls.Add(msoControlButton)
.Caption = "Reset menus"
.OnAction = "Test"
End With
End With
End Sub
'Alters the right click menu in a chart
Sub AlterWorkChartPopup()
Dim oCtrl As Object
With Application.CommandBars("Plot Area")
'Clear the existing menus
For Each oCtrl In .Controls
oCtrl.Delete
Next
'Add a new menu
With .Controls.Add(msoControlButton)
.Caption = "Reset Menus"
.OnAction = "Test"
End With
End With
End Sub
' Routine will be called by the new menu items, to reset menus to default
Sub Test()
' Reset the menus
Application.CommandBars("Cell").Reset
Application.CommandBars("Plot Area").Reset
MsgBox "Reset menus to default succeeded!"
End Sub
Views 1,079
Downloads 410
CodeID
DB ID