取消保护文件夹中所有二进制工作簿中的所有工作表,并在不受保护的情况下保存它们
Unprotect all sheets in all binary workbooks in a folder and save them unprotected
- 我有一个包含 .xlsb 个工作簿的文件夹。
- 每本练习册有 5 张,均有密码保护。
- 密码对所有工作表、所有工作簿通用。
- 工作簿本身没有密码。
如何取消保护所有工作簿的所有工作表并将它们保存为未保护?
我找到了以下代码,但它无法满足我的需要(它仅适用于活动工作簿)。
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
像这样:
任何取消保护工作表的失败都会立即报告window
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
- 我有一个包含 .xlsb 个工作簿的文件夹。
- 每本练习册有 5 张,均有密码保护。
- 密码对所有工作表、所有工作簿通用。
- 工作簿本身没有密码。
如何取消保护所有工作簿的所有工作表并将它们保存为未保护?
我找到了以下代码,但它无法满足我的需要(它仅适用于活动工作簿)。
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
像这样:
任何取消保护工作表的失败都会立即报告window
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