【问题标题】:Hiding Rows on Another Sheet in a Protected Workbook在受保护的工作簿中隐藏另一张工作表上的行
【发布时间】:2020-01-25 19:59:34
【问题描述】:

我有一个工作簿,在 Sheet2 上有一个带有 ActiveX 复选框的目录。

如果用户选中其中一个复选框,它将在另一张纸上隐藏该部分。

我需要将其作为受保护的工作簿。

当我点击一个复选框时,我收到这个错误:

“您尝试更改的单元格或图表位于受保护的工作表上。要进行更改,请单击“审阅”选项卡中的取消保护工作表。”

保护工作簿的代码:

Private Sub Workbook_Open()
Dim wSheetName As Worksheet
For Each wSheetName In Worksheets
    wSheetName.Protect Password:="pass", UserInterfaceOnly:=True
Next wSheetName
End Sub

复选框的代码:

Private Sub CheckBox1_Click()
Application.ScreenUpdating = False

If CheckBox1.Value = True Then
    Sheet1.Rows("4:9").EntireRow.Hidden = True
Else:
    Sheet1.Rows("4:9").EntireRow.Hidden = False
End If

Application.ScreenUpdating = True
End Sub

【问题讨论】:

  • 取消保护工作表进行隐藏,重新保护工作表?

标签: excel vba


【解决方案1】:

我将 ThisWorkbook 限定符添加到 Sub。

变化:

Private Sub Workbook_Open()
Dim wSheetName As Worksheet
For Each wSheetName In Worksheets
    wSheetName.Protect Password:="pass", UserInterfaceOnly:=True

Next wSheetName
End Sub

收件人:

Private Sub Workbook_Open()

    Dim wSheetName As Worksheet
    For Each wSheetName In ThisWorkbook.Worksheets
        wSheetName.Protect Password:="pass", UserInterfaceOnly:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True

    Next wSheetName
    End Sub

【讨论】:

  • 不幸的是仍然收到错误消息。现在我也看到“对象不支持此属性或方法”错误消息...
  • 我在答案中添加了AllowFormattingColumns 和AllowFormattingRows。取出ThisWorkbook 看看是否有效。
猜你喜欢
  • 2017-10-18
  • 1970-01-01
  • 2020-10-05
  • 2023-03-27
  • 1970-01-01
  • 2015-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多