无需知道密码即可解锁受保护的工作簿

时间:2016-10-21 20:09:26

标签: excel vba excel-vba

我遇到了问题,我创建了一个自动填充报表,其中包含从网站下载的电子表格。然而,这些表格受密码保护,我找到了解锁工作簿的代码,而无需提供密码,但是在2016年excel上工作还没有人知道其他方式吗?

这是我的代码:

Sub UnProtect_Excel_WorkSheet()
    'Unlock Protect Excel Worksheet
    Dim i1 As Integer, i2 As Integer, i3 As Integer, j1 As Integer, j2 As Integer, j3 As Integer
    Dim k1 As Integer, k2 As Integer, k3 As Integer, l1 As Integer, l2 As Integer, l3 As Integer
    Dim a As Double

    On Error Resume Next
    a = 0
    'Try all Possible Alternate Combination Password
    For i1 = 65 To 66: For i2 = 65 To 66: For i3 = 65 To 66
    For j1 = 65 To 66: For j2 = 65 To 66: For j3 = 65 To 66
    For k1 = 65 To 66: For k2 = 65 To 66: For k3 = 65 To 66
    For l1 = 65 To 66: For l2 = 65 To 66: For l3 = 32 To 126
        ThisWorkbook.Sheets(1).Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(j1) & Chr(j2) & Chr(j3) & Chr(k1) & Chr(k2) & Chr(k3) & Chr(l1) & Chr(l2) & Chr(l3)
        a = a + 1
        ThisWorkbook.Sheets(2).Cells(a, 1) = Chr(i1) & Chr(i2) & Chr(i3) & Chr(j1) & Chr(j2) & Chr(j3) & Chr(k1) & Chr(k2) & Chr(k3) & Chr(l1) & Chr(l2) & Chr(l3)

        'Check if the Protection is Removed
        If ActiveSheet.ProtectContents = False Then
            MsgBox "One usable password is " & Chr(i1) & Chr(i2) & Chr(i3) & Chr(j1) & Chr(j2) & Chr(j3) & Chr(k1) & Chr(k2) & Chr(k3) & Chr(l1) & Chr(l2) & Chr(l3)
            Exit Sub
        End If

        'Exit Loop
    Next: Next: Next: Next: Next: Next
    Next: Next: Next: Next: Next: Next
End Sub

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我发现的解决方案非常简单 - 只需将文档保存为.xls并运行脚本。

如果行数少于65K,这是一个可行的解决方案。