Right Click Context menu

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,285
Office Version
  1. 365
Platform
  1. Windows
I use VBA to recreate my right click menu on a work book created in 2019.

At the time I used this piece of code to reset the menu when I swapped between books and another similar when i swapped back

VBA Code:
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
'resets right click menu when worksheet is not in focus
    Application.CommandBars("Cell").Reset
End Sub

Am I right in saying this is no longer required? it seems each new book has a completely independent menu


Not sure what is going on.

It seems the windowdeactivate is required so I can swap to a different book, but I have completely removed this code and it still works....
But I don't understand why.


VBA Code:
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
'Sets right click menu when worksheet comes into focus
Application.Calculation = xlCalculationAutomatic
Application.CommandBars("Cell").Reset
For Each Item In Application.CommandBars("Cell").Controls
    Item.Delete
Next Item

    With Application.CommandBars("Cell").Controls.Add(Temporary:=True)
        .Caption = "Main Update"
        .Style = msoButtonCaption
        .OnAction = "Main_Update"
    End With
   
    With Application.CommandBars("Cell").Controls.Add(Temporary:=True)
        .BeginGroup = True
        .Caption = "Expedite"
        .Style = msoButtonCaption
        .OnAction = "expedite_report"
    End With

'...Lots more repeated....

End Sub
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,215,227
Messages
6,123,743
Members
449,116
Latest member
alexlomt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top