A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
sht.Protect csConstant, AllowFormattingRows:=pbAllowFormat, UserInterfaceOnly:=True
Add
DrawingObjects:=False
to the line above.
Andreas.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
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.
Answer accepted by question author
sht.Protect csConstant, AllowFormattingRows:=pbAllowFormat, UserInterfaceOnly:=True
Add
DrawingObjects:=False
to the line above.
Andreas.
Once again you help me out of a tight spot Andreas.
Thank you very much.