View Single Post
 
Old 12-24-2020, 08:54 PM
Logit Logit is offline Windows 10 Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
Ok ... did a little research. Try this version.
Paste both in the THISWORKBOOK module.

Code:
Option Explicit

'Sub Auto_Close()
'Application.CommandBars("Cell").Reset
'End Sub

Private Sub Workbook_Deactivate()
    On Error Resume Next
           With Application
                .CommandBars("Cell").Controls("My Macro").Delete
            End With
    On Error GoTo 0
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cBut As CommandBarButton
    On Error Resume Next
        With Application
            .CommandBars("Cell").Controls("My Macro").Delete
            Set cBut = .CommandBars("Cell").Controls.Add(Temporary:=True)
        End With

        With cBut
           .Caption = "My Macro"
           .Style = msoButtonCaption
           .OnAction = "My_Macro"
        End With
    On Error GoTo 0
End Sub
Reply With Quote