在受保护模式下显示某些合并单元格的注释

时间:2017-01-07 18:49:08

标签: excel vba

我需要在某些已解锁的合并单元格中显示注释。

我在网上找到了代码来显示工作簿中的所有注释。这不起作用,因为我的工作簿需要受到保护,这意味着宏将查看锁定的单元格并过早结束。

WM_PAINT

我需要知道如何指定具有注释的合并范围。第一个合并范围是" C7:C8-E7:E8"。如果我知道如何做一个范围,我会想办法如何做其他范围。

细胞看起来像的图片以及按钮:

enter image description here

这不适合学校。

2 个答案:

答案 0 :(得分:2)

在尝试操作工作表之前,必须首先取消保护工作表,并且在应用更改后,还原保护。

  For Each ws In ActiveWorkbook.Sheets
      ws.Unprotect
      Set allCommentRng = ws.Cells.SpecialCells(xlCellTypeComments)
      For Each Rng In allCommentRng
          Rng.Comment.Visible = True
      Next Rng
      ws.Protect
  Next ws

上面的示例意味着没有密码保护。要克服工作表的密码保护,请使用:

ws.Unprotect Password:="yourpasswordhere"
ws.Protect Password:="yourpasswordhere"

答案 1 :(得分:1)

如果在运行宏之前取消保护工作表并在以下情况下重新保护,那该怎么办:

Sub Show_Comment()
On Error Resume Next
For Each ws In ActiveWorkbook.Sheets
    ws.unprotect
    Set allCommentRng = ws.Cells.SpecialCells(xlCellTypeComments)
    For Each Rng In allCommentRng
        Rng.Comment.Visible = True
    Next Rng
    ws.protect
Next ws
On Error GoTo 0
End Sub
相关问题