View Single Post
 
Old 12-24-2020, 10:42 AM
coffent coffent is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default Add item to context menu for a specific workbook

I want to add an item to the context (right-click) menu for a specific workbook. The code below does what I want, except that it adds the item for all workbook menus. Is there some way to limit the scope to a single workbook?

Sub AddItemShortCutMenu()
Dim Shortcut As CommandBar
Dim NewItem As CommandBarButton

Set Shortcut = Application.CommandBars("Cell")
Set NewItem = Shortcut.Controls.Add(Type:=msoControlButton)
With NewItem
.Caption = "Custom Action"
.OnAction = "CustomSubroutine" 'The subroutine must be located in Module1 for some reason
End With
End Sub
Reply With Quote