Share via

UserInterfaceOnly:=True will not allow comment editing

Anonymous
2016-01-18T12:34:06+00:00

I am protecting my sheets with UserInterfaceOnly:=True, but Comment manipulation is behaving in a manner I cannot comprehend.

When I unprotect the sheet, everything works (obviously). But if the sheet is protected with UserInterfaceOnly:=True, while the ClearComments statement does not produce a runtime error ( although it does not actually clear the cell comment ), the AddComment statement produces a runtime error. In any case, my code does not work with UserInterfaceOnly:=True.

What am I doing wrong here?

***************************************************************************************

Public Const csConstant As String = "MyPassword"

Dim rCompComment As Range

Set rCompComment = ThisWorkbook.Worksheets("Entry").Range("C_CommentCompindex")

Call SetProtection("On") ' further down

.........

rCompComment.ClearComments

rCompComment.AddComment "new comment"

..........


Public Sub SetProtection(psOnOff As String, Optional pbAllowFormat As Boolean)

Dim sht As Worksheet

If IsMissing(pbAllowFormat) Then pbAllowFormat = False

If psOnOff = "On" Then

   For Each sht In Worksheets

         sht.Protect csConstant, AllowFormattingRows:=pbAllowFormat, UserInterfaceOnly:=True

   Next

ElseIf psOnOff = "Off" Then

   For Each sht In Worksheets

         'sht.Unprotect    '  this has been commented out in order to allow full VBA run with UserInterfaceOnly:=True

   Next

End If

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Andreas Killer 144.1K Reputation points Volunteer Moderator
2016-01-18T15:48:41+00:00

         sht.Protect csConstant, AllowFormattingRows:=pbAllowFormat, UserInterfaceOnly:=True

Add

  DrawingObjects:=False

to the line above.

Andreas.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-01-18T16:05:34+00:00

    Once again you help me out of a tight spot Andreas.

    Thank you very much.

    Was this answer helpful?

    0 comments No comments