AllInternalPasswords Document Explanation and VBA
AllInternalPasswords Document Explanation and VBA
1. You must remember that removing password protect may be a breach of law and/or your
employment contract. It should only be done if you clearly have the right to do so.
2. Microsoft are fairly relaxed over my publication of this process: it cut down the
calls to their Help Desk and increased the Help Desk success ratio. I’m not sure they
appreciate my comments on ‘fairy floss’ but since they call it ‘cotton candy’, they
probably don’t understand!
4. You’ll need a non-networked computer because networked computers should never allow
users to create and run the removal code. Cost will be very low and I’ll there will be other uses for it
5. Now pass this Word file over to someone at beginner’s level in Excel Visual Basic For Applications
(VBA)
I acknowledge publication of an algorithm but no more by Bob McCormick and the signifant
Tidying up of my ‘crude’ coding by Excel MVP JE McGimpsey. I also acknowledge that I started
the idea early Boxing Day 2002 and published my ‘crude’ code later that day for a distressed
poster on a user group. ‘JE’ was similarly at a loose end and offered, very politely, to remove
my offences against all the rules of programming.
Word Document:
A little ‘history’ will help you understand the logic behind the 2012 onwards process.
Then in 2012 Microsoft claimed increased strength of these passwords and that they could
not now be broken. I begged to differ!
The solution is
1. Use the File > Save As command and to select the option of saving the workbook as a pre-2012
workbook. You will lose those wonderful ‘fairy floss’ features built into 2012 onwards. But only
rarely will the user have employed features that impact upon quantitative results.
2. In new workbook you can then follow steps 1-5 above.
3. With passwords removed you can now save the file back up to your normal Excel version.
4. You’ve lost all the 2012 onwards features but, probably crucially, the data and formulae that were
protected are now unprotected.
Application.ScreenUpdating = False
With ActiveWorkbook
WinTag = .ProtectStructure Or .ProtectWindows
End With
ShTag = False
For Each w1 In Worksheets
ShTag = ShTag Or w1.ProtectContents
Next w1
If Not ShTag And Not WinTag Then
MsgBox MSGNOPWORDS1, vbInformation, HEADER
Exit Sub
End If
MsgBox MSGTAKETIME, vbInformation, HEADER
If Not WinTag Then
MsgBox MSGNOPWORDS2, vbInformation, HEADER
Else
On Error Resume Next
Do 'dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
With ActiveWorkbook
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If .ProtectStructure = False And _
.ProtectWindows = False Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND1, _
"$$", PWord1), vbInformation, HEADER
Exit Do 'Bypass all for...nexts
End If
End With
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
If WinTag And Not ShTag Then
MsgBox MSGONLYONE, vbInformation, HEADER
Exit Sub
End If
On Error Resume Next
For Each w1 In Worksheets
'Attempt clearance with PWord1
w1.Unprotect PWord1
Next w1
On Error GoTo 0
ShTag = False
For Each w1 In Worksheets
'Checks for all clear ShTag triggered to 1 if not.
ShTag = ShTag Or w1.ProtectContents
Next w1
If ShTag Then
For Each w1 In Worksheets
With w1
If .ProtectContents Then
On Error Resume Next
Do 'Dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If Not .ProtectContents Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND2, _
"$$", PWord1), vbInformation, HEADER
'leverage finding Pword by trying on other sheets
For Each w2 In Worksheets
w2.Unprotect PWord1
Next w2
Exit Do 'Bypass all for...nexts
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
End With
Next w1
End If
MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER
End Sub