Disable Insert Comment on Command bar

Bering

Board Regular
Joined
Aug 22, 2018
Messages
185
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I would like to disable Insert Comment when right clicking on any cell of a spreadsheet.

Using the code below I have managed to disable "Delete Comment, Edit Comment, Show/Hide Comment", however this does not seem to work for Insert Comment. Any ideas?

Thank you.

VBA Code:
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
On Error Resume Next


         With Application.CommandBars("Cell")

            .Controls("Insert Comment").Enabled = False
            .Controls("Delete Comment").Enabled = False
            .Controls("Edit Comment").Enabled = False
            .Controls("Show/Hide Comments").Enabled = False


        End With

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try:

Application.CommandBars("Cell").FindControl(ID:=2031).Enabled = False
 
Upvote 0
Thanks Dante, I tried that but it did not work ?

I will use the code below as a workaround:

VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

Cancel = True
MsgBox "Right click disabled on this sheet!"
End Sub

However, I have now realised that users could still insert/delete/edit comments from the review menu of the ribbon :unsure:

I tried this in Thisworkbook but nada.... If that can help I am using Microsoft Office Professional Plus 2016...

Code:
Private Sub Workbook_Activate()
    Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = Not Application.DisplayStatusBar
    ActiveWindow.DisplayWorkbookTabs = False

End Sub

Private Sub Workbook_Deactivate()

    Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
    Application.DisplayFormulaBar = True
    Application.DisplayStatusBar = True
    ActiveWindow.DisplayWorkbookTabs = True

End Sub

Thank you
 
Upvote 0
Thanks Dante, I tried that but it did not work ?

I will use the code below as a workaround:

VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox "Right click disabled on this sheet!"
End Sub
Thank you

Check the following:

@DanteAmor
- is this an Excel version issue perhaps ?
- did you test on Excel 2007
View attachment 2040

It works for me in the 2007 version
 
Upvote 0
Solution
Hello, I have removed some conditional formatting from my code and now everything works as expected...
Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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