首页 > 解决方案 > 通过宏保护具有多个工作表的整个工作簿

问题描述

我想保护具有多张工作表的整个工作簿。还需要对所有纸张进行保护。有没有办法做到这一点?

标签: excelvbapassword-protection

解决方案


你可以从这里开始:

Sub protect()
Dim s As String
Dim ws As Worksheet
s = InputBox("Enter Password", "Protection", "")
For Each ws In ThisWorkbook.Worksheets
    ws.protect s
Next ws
ThisWorkbook.protect s
End Sub

Sub unprotect()
Dim s As String
Dim ws As Worksheet
s = InputBox("Enter Password", "Protection", "")
For Each ws In ThisWorkbook.Worksheets
    ws.unprotect s
Next ws
ThisWorkbook.unprotect s
End Sub

更改以与其他工作簿和/或密码一起使用。


推荐阅读