如何取消保护所有工作簿的所有工作表并将其保存为不受保护?
我找到了以下代码,但它无法满足我的需求(仅适用于活动工作簿)。
Sub unprotect_all_sheets()
On Error Goto booboo
unpass = InputBox("password")
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Unprotect Password:=unpass
Next
Exit Sub
booboo: MsgBox "There is s problem - check your password, capslock, etc."
End Sub
答案 0 :(得分:0)
这样的事情:
在立即窗口中报告任何未能取消保护的工作表
Sub LoopThroughFiles()
Dim StrFile As String
Dim Wb As Workbook
Dim ws As Worksheet
Dim strFol As String
Dim strPass As String
'password
strPass = "tested"
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
'folder to work in
strFol = "c:\temp\"
StrFile = Dir(strFol & "*.xls*")
Do While Len(StrFile) > 0
Set Wb = Workbooks.Open(strFol & StrFile)
For Each ws In Wb.Worksheets
On Error Resume Next
ws.Unprotect strPass
If Err.Number <> 0 Then Debug.Print strFol & StrFile & " " & ws.Name
On Error GoTo 0
Next
Wb.Save
Wb.Close
StrFile = Dir
Loop
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub