Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50070

Disable Delete Comment, Edit Comment, Show/Hide Comment

$
0
0
Hi,

I have my workbook set up such that when a username and password is entered via a userform, certain cells in the worksheet are unprotected. I would like to disable Delete Comment, Edit Comment and Show/Hide Comment in the right-click command menu even when the worksheets are unprotected.

Here is what I have:
Code:

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    If Sheets("User Names").Range("D5").Interior.ColorIndex = 3 Then
        Application.CommandBars("Cell").Controls("Delete Comment").Enabled = True
        Application.CommandBars("Cell").Controls("Edit Comment").Enabled = True
        Application.CommandBars("Cell").Controls("Show/Hide Comments").Enabled = True
 
    Else
        Application.CommandBars("Cell").Controls("Delete Comment").Enabled = False
        Application.CommandBars("Cell").Controls("Edit Comment").Enabled = False
        Application.CommandBars("Cell").Controls("Show/Hide Comments").Enabled = False
    End If
End Sub

Code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.ScreenUpdating = False
    Application.EnableEvents = False
   
    ' Reset Edit/Delete Comment function on Excel when the user closes the file.

    Application.CommandBars("Cell").Controls("Show/Hide Comments").Enabled = True
    Application.CommandBars("Cell").Controls("Insert Comment").Enabled = True
    Application.CommandBars("Cell").Controls("Delete Comment").Enabled = True
    Application.CommandBars("Cell").Controls("Edit Comment").Enabled = True

    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub

My Problem:
  1. I am getting "Run-time error 5: Invalid procedure call or argument" error at Application.CommandBars("Cell").Controls("Edit Comment").Enabled = True and Application.CommandBars("Cell").Controls("Insert Comment").Enabled = True. Why is this?
  2. When I open another Excel workbook, the Insert Comment option is greyed out. Why is this?

Viewing all articles
Browse latest Browse all 50070

Trending Articles