保护/取消保护图表

时间:2014-01-23 16:52:09

标签: excel vba excel-vba

因此,当我的宏运行时,我有这些简单的sub来解除保护而不是保护东西,唯一的问题是我的一些工作表实际上是图表,并且在调用这些子服务器时它们不受保护。如何更改我的代码以合并图表?谢谢!

Sub UnprotectAll()

  Dim AdminPassword As String
  AdminPassword = "password"

  ActiveWorkbook.Unprotect ("Evaluate(AdminPassword)")

  For Each sh In ActiveWorkbook.Worksheets
    sh.Unprotect Password:=AdminPassword
  Next sh

End Sub

Sub ProtectAll()

  Dim AdminPassword As String
  AdminPassword = "password"

  ActiveWorkbook.Protect ("Evaluate(AdminPassword)")

  For Each sh In ActiveWorkbook.Worksheets
    sh.Protect Password:=AdminPassword
  Next sh

End Sub

1 个答案:

答案 0 :(得分:4)

ActiveWorkbook.Worksheets替换为ActiveWorkbook.Sheets