a big problem after run macro in exel

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,433
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i have a big problem when i tested this code type of protection it hide command bar when i right click does not show but when i change to true it also doesn't change it supposes showing the menu when right click
this is the macro
VBA Code:
Sub cc()
  Application.CommandBars("Worksheet Menu Bar").Enabled = false

End Sub
thanks

thanks
 
Try changing your SheetBeforeRightClick code to this :
VBA Code:
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

    Dim cBut As CommandBarButton
    Dim cBut2 As CommandBarButton
    Dim cBut3 As CommandBarButton
    Dim cBut4 As CommandBarButton
    Dim cBut5 As CommandBarButton
    Dim cBut6 As CommandBarButton
    Dim cBut7 As CommandBarButton
    Dim cBut8 As CommandBarButton


    With Application
    
        On Error Resume Next
        
            .CommandBars("Cell").Controls("Hide Menu").Delete
            .CommandBars("Cell").Controls("Show Menu").Delete
            
            .CommandBars("Row").Controls("Hide Menu").Delete
            .CommandBars("Row").Controls("Show Menu").Delete
            
            .CommandBars("Column").Controls("Hide Menu").Delete
            .CommandBars("Column").Controls("Show Menu").Delete
            
            .CommandBars("Ply").Controls("Hide Menu").Delete
            .CommandBars("Ply").Controls("Show Menu").Delete
            
        On Error GoTo 0        

            Set cBut = .CommandBars("Cell").Controls.Add(Temporary:=True)
            Set cBut2 = .CommandBars("Cell").Controls.Add(Temporary:=True)
            
            Set cBut3 = .CommandBars("Row").Controls.Add(Temporary:=True)
            Set cBut4 = .CommandBars("Row").Controls.Add(Temporary:=True)
            
            Set cBut5 = .CommandBars("Column").Controls.Add(Temporary:=True)
            Set cBut6 = .CommandBars("Column").Controls.Add(Temporary:=True)
 
            Set cBut7 = .CommandBars("Ply").Controls.Add(Temporary:=True)
            Set cBut8 = .CommandBars("Ply").Controls.Add(Temporary:=True)

    End With
        
        With cBut
           .Caption = "Hide Menu"
           .Style = msoButtonCaption
           .OnAction = "hideMenu"
        End With
        
        With cBut2
           .Caption = "Show Menu"
           .Style = msoButtonCaption
           .OnAction = "shwMenu"
        End With
        
        With cBut3
           .Caption = "Hide Menu"
           .Style = msoButtonCaption
           .OnAction = "hideMenu"
        End With

        With cBut4
           .Caption = "Show Menu"
           .Style = msoButtonCaption
           .OnAction = "shwMenu"
        End With
        
        With cBut5
           .Caption = "Hide Menu"
           .Style = msoButtonCaption
           .OnAction = "hideMenu"
        End With

        With cBut6
           .Caption = "Show Menu"
           .Style = msoButtonCaption
           .OnAction = "shwMenu"
        End With
        
        With cBut7
           .Caption = "Hide Menu"
           .Style = msoButtonCaption
           .OnAction = "hideMenu"
        End With

        With cBut8
           .Caption = "Show Menu"
           .Style = msoButtonCaption
           .OnAction = "shwMenu"
        End With

End Sub
 
Upvote 0

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.
Your download workbook ( aaa.xlsm ) works as it should on my computer.

I am not certain what is happening there.
 
Upvote 0
hi, jafaar i put your code as you said i no know how works i saved and closed then open again the problem the menu shows when i right click into any cell but when i select column or row and right click the menu doesn't show i no know what's wrong
 
Upvote 0
.
Made an edit to the existing code.

Replace the macro Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) with the
macro below :


VBA Code:
'Add Excel Right Click Menu

'Excel VBA: Adding a Command Button to the Excel Right Click Pop-up Toolbar/Command Bar
'Current Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!

'Adding a Command Button to the Excel Right Click Pop-up Toolbar/Command Bar

'Note how the code first deletes any existing menu option called "My Macro". This stops the code adding an additional custom menu options and ensures only one custom menu option is available at any one time. The use of Temporary:=True ensures this menu option is deleted whenever Excel closes. Without it, it's possible to have you custom menu option showing in another Workbook. This is also why we make use of the Workbook_Deactivate Event. That is, if we activate another Workbook while this one is open, the custom menu option is deleted.

'The macro that is run whenever this custom menu option is clicked is called "My_Macro". You should change this, and the caption, to suit your needs.

'The code below should be placed in Private Module of the Workbook Object (ThisWorkbook). To get there quickly, right click on the Excel icon, top left next to File and choose View Code.




Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

Dim cBut As CommandBarButton
Dim cBut2 As CommandBarButton



    On Error Resume Next

        With Application

            .CommandBars("Cell").Controls("Hide Menu").Delete
            .CommandBars("Cell").Controls("Show Menu").Delete

            Set cBut = .CommandBars("Cell").Controls.Add(Temporary:=True)
            Set cBut2 = .CommandBars("Cell").Controls.Add(Temporary:=True)

        End With

        

        With cBut

           .Caption = "Hide Menu"

           .Style = msoButtonCaption

           .OnAction = "hideMenu"

        End With
        
        With cBut2

           .Caption = "Show Menu"

           .Style = msoButtonCaption

           .OnAction = "shwMenu"

        End With


    On Error GoTo 0

End Sub
 
Upvote 0
sorry logit also this doesn't work , is it something in setting windows10 or office 2016?
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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