Friday, 17 December 2010

Handy Sub to Unlock Protected Excel Worksheet

Had a request a few weeks ago from someone who needed to unprotect an Excel sheet which had been protected by someone who was no longer with the company so they could not get the Password.

here is the procedure I developed,

Sub PasswordReset()

Dim ia As Integer, ib As Integer, ic As Integer
Dim id As Integer, ie As Integer, ig As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer

On Error Resume Next

For ia = 65 To 66: For ib = 65 To 66: For ic = 65 To 66
For id = 65 To 66: For ie = 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 ig = 32 To 126
ActiveSheet.Unprotect Chr(ia) & Chr(ib) & Chr(ic) & _
Chr(id) & Chr(ie) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(ig)
If ActiveSheet.ProtectContents = False Then
MsgBox "Your Sheet has Been Unlocked Using " & Chr(ia) & Chr(ib) & _
Chr(ic) & Chr(id) & Chr(ie) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(ig)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub

So next time you forget your password and need to unprotect a sheet just add this to the VBA window and run the Module. Hey Presto.

No comments:

Post a Comment