Reputation: 21
I'm stuck with a problem, I'm creating a automation to automatically fill a report with spreadsheets downloaded from a website. however these sheets comes protected with a password, I've found a code to unlock the workbook without having to provide a password, however isn't working on excel 2016, anybody knows some other way?
Here's the code I have:
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
Upvotes: 1
Views: 3806
Reputation: 15
I've had the same problem. The solution I found is quite simple - just save the document as .xls and run the script.
This is a working solution if you have less than 65K rows.
Upvotes: 1