【问题标题】:Unprotect all sheets in all binary workbooks in a folder and save them unprotected取消保护文件夹中所有二进制工作簿中的所有工作表并将其保存为不受保护
【发布时间】:2017-07-12 16:35:01
【问题描述】:
  • 我有一个包含 .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

【问题讨论】:

  • 在 R 中,您可以使用来自 excel.linkxl.read.file 来读取受密码保护的电子表格。 stackoverflow.com/questions/34233738/…
  • @Brad 您的链接是关于保护,而不是取消保护。请撤回重复的标志。
  • @SamFirke excel.link 不适用于 .xlsb
  • 您自己尝试过什么吗?好像是刚在网上找的代码,没用,所以来这里问问。

标签: r excel vba password-protection


【解决方案1】:

类似这样的:

任何取消保护工作表的失败都会在即时窗口中报告

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多