Friday, February 25, 2011

Crack Excel Workbook/Worksheet Protection

Press Alt F11 to open the VBA editor and copy paste the code

Select the worksheet in Project Explorer press F7 and Copy Paste the below code in code window.

Press run on the ribbion or press F5.

You can call this Macro from some other macro if u dont want to go to VBA and run it.

Create a button on the sheet and on click event call the macro ExcelProtectionCracker.

-----------------------------------------------------------------------------------------------
Public Sub ExcelProtectionCracker()
' Breaks worksheet and workbook structure Protection. Bob McCormick
' probably originator of base code algorithm modified to Crack
' Excel Workbook Structure/Windows and Sheet prptections.
'
' Arpit Sharda 20-Feb-2010 (Version 1.1)
' Reveals Hashed passwords NOT original passwords

Const DBLSPACE As String = vbNewLine & vbNewLine
Const AUTHORS As String = DBLSPACE & vbNewLine & _
"Adapted from Bob McCormick base code by " & _
"Arpit Sharda"
Const HEADER As String = "Excel Protection Cracker"
Const VERSION As String = DBLSPACE & "Version 1.1.1 2010-Feb-20"
Const FEEDBACK As String = DBLSPACE & "Please feedback or report any failure " & _
"to http://discovarp.blogspot.com/"

Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _
"now be free of all password protection, so make sure you:" & _
DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _
DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _
DBLSPACE & "Also, remember that the password was " & _
"put there for a reason. Don't stuff up crucial formulas " & _
"or data." & DBLSPACE & "Access and use of some data " & _
"may be an offense. If in doubt, don't."

Const NOPROTECTIONMSG As String = "Workbook Structure/Window Protection and Worksheet Protection is not Enabled. " & _
"No Password Found." & AUTHORS & VERSION

Const NOBOOKPROTECTION As String = "Workbook Structure/Window Protection is not Enabled " & DBLSPACE & _
"Proceeding to unprotect sheets." & AUTHORS & VERSION

Const TIMEALERT As String = "This may take some time " & _
"to calculate the Hashed Password." & DBLSPACE & "Press OK to Continue. " & AUTHORS & VERSION

Const BOOKPROTECTIONFOUND As String = "You had a WorkBook " & _
"Structure/Windows Protection Enabled." & DBLSPACE & _
"The Hashed password found was: " & DBLSPACE & "$$" & DBLSPACE & _
"Now continuing to check and clear other Protection." & AUTHORS & VERSION

Const SHEETPROTECTIONFOUND As String = "You had a Worksheet " & _
"password set." & DBLSPACE & "The Hashed password found was: " & _
DBLSPACE & "$$" & DBLSPACE & DBLSPACE & "Now continuing to check and clear " & _
"other passwords." & AUTHORS & VERSION

Const ONLYBOOKPROTECTION As String = "Only Workbook Structure/Window Protection was Enabled " & _
"Hashed Password Matched and Workbook Structure/Window was just Unlocked." & _
ALLCLEAR & AUTHORS & VERSION & FEEDBACK


Dim ws1 As Worksheet, ws2 As Worksheet

' Variables used to create Hashed Password values using nested for loops
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer

' Hashed Password found
Dim HASHEDPASS As String

' Flag to check Sheet Protect and Window/Structure Protect
Dim SheetFlag As Boolean, WinFlag As Boolean

' Default value sheet Protection is disabled, Window/Structure Protection disabled
SheetFlag = False
WinFlag = False

Application.ScreenUpdating = False
With ActiveWorkbook
' On ActiveWorkbook check for Structure/Window Protection
WinFlag = .ProtectStructure Or .ProtectWindows
End With

' Check for all WorkSheets in the ActiveWorkbook for Sheet Protection
For Each ws1 In Worksheets
SheetFlag = SheetFlag Or ws1.ProtectContents
Next ws1

'-------------------------------------------------------------------------------------------------------------------
'| SheetFlag | Structure/Window Flag (WinFlag) | Description |
'--------------------------------------------------------------------------------------------------------------------
'| 0 | 0 | - Both Protection are Disabled. |
'| 0 | 1 | - Only Window/Structure Protection is Enabled. |
'| 1 | 0 | - Only Sheet Protection is Enabled. |
'| 1 | 1 | - Both Protection are Enabled. |
'--------------------------------------------------------------------------------------------------------------------

' SheetFlag - 0 WinFlag - 0 ===> Both Protection are Disabled.
If Not SheetFlag And Not WinFlag Then
' No Password found on the workbook. Neither Sheet protection nor Window/Structure Protection
MsgBox NOPROTECTIONMSG, vbInformation, HEADER
Exit Sub
End If

' Display Time Alert
Dim iReturn As Integer
iReturn = MsgBox(TIMEALERT, vbOKCancel, HEADER)

' Check pressed button
If iReturn = vbCancel Then
Exit Sub
End If

' 0 | 1 - Only Window/Structure Protection is Enabled.
' 1 | 0 - Only Sheet Protection is Enabled.
' 1 | 1 - Both Protection are Enabled.

If WinFlag Or SheetFlag Then
On Error Resume Next

' WinFlag - 1 Window/Structure Protection is Enabled.
If WinFlag Then
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)

' Save the Hased Password
If .ProtectStructure = False And _
.ProtectWindows = False Then
HASHEDPASS = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

' Window/Structure Protection Unlocked.
MsgBox Application.Substitute(BOOKPROTECTIONFOUND, _
"$$", HASHEDPASS), 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 ' End Dummy DO Loop
On Error GoTo 0

' WinFlag - 0 Only Window/Structure Protection is not Enabled.
Else
MsgBox NOBOOKPROTECTION, vbInformation, HEADER
End If


If WinFlag And Not SheetFlag Then
MsgBox ONLYBOOKPROTECTION, vbInformation, HEADER
Exit Sub
End If

If SheetFlag Then
On Error Resume Next
For Each ws1 In Worksheets
'Attempt clearance with HASHEDPASSWORD
ws1.Unprotect HASHEDPASS
Next ws1
On Error GoTo 0
SheetFlag = False
For Each ws1 In Worksheets
'Checks for all clear SheetFlag triggered to 1 if not.
SheetFlag = SheetFlag Or ws1.ProtectContents
Next ws1
If SheetFlag Then
For Each ws1 In Worksheets
With ws1
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
HASHEDPASS = 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(SHEETPROTECTIONFOUND, _
"$$", HASHEDPASS), vbInformation, HEADER
'leverage finding HASHEDPASS by trying on other sheets
For Each ws2 In Worksheets
ws2.Unprotect HASHEDPASS
Next ws2
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 ws1
End If
End If
MsgBox ALLCLEAR & AUTHORS & VERSION & FEEDBACK, vbInformation, HEADER
End If
End Sub

-----------------------------------------------------------------------------------------------

20 comments:

  1. Alternatively
    Do the follwoing:

    1. Create a new simple excel file.
    2. In the VBA part, set a simple password (say - 1234).
    3. Save the file and exit.
    4. Open the file you just created with a simple editor.
    5. Copy the lines starting with the following keys:

    CMG=....
    DPB=...
    GC=...

    6. with a simple editor (again), open the excel file you don;t know
    the VBA password for,
    and paste the above copied lines from the dummy file.
    7. save the excel file and exit.
    8. Now, open the excel file you need to see the VBA code in. The
    password for the VBA code
    will simply be 1234

    Simply works...

    ReplyDelete
  2. Replies
    1. well duh! Its for excel versions before 2013. Things have change in 2013 version.

      Delete
    2. if I am right, you can save the 2013 to 2007 extension then open it after that to apply the code then change it to any extension. :)

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Genius! This was the only script that was able to unlock my "workbook" many other scripts could only unlock worksheet.

    ReplyDelete
  5. Where Do I paste this script. My workbook was protected, I am not able to open without password. how can I paste vba code in VBA Editor.

    ReplyDelete
    Replies
    1. Nani, you have different issue than the one given by Arpit, you need a code to open the protected excel sheet

      Delete
  6. Many thanks Arpit Sharda, you are really a great programmer, I really cannot but thank you for your excellent participation. I have one more question " if do not mind, is there any VBA code to break Word Document Password & Word editable Protection" Appreciate your help.

    ReplyDelete
  7. Great post, tried many scripts, only this script saved me.

    ReplyDelete
  8. Use Excel Password Recovery software easily recover lost Excel file password and unlock Excel file after then fastly re-open Excel (xls or xlsx ) file. It is right way to remove Excel file password with all Microsoft Excel users very simply read Microsoft Excel file.

    Read more:- http://www.mannatsoftware.com/stellar-phoenix-excel-password-recovery.html

    ReplyDelete
  9. I used for this purpose Manyprog Excel Password Recovery. It will help restore password to Excel file, and can recover the password to Excel sheet. http://manyprog.com/excel-password-recovery.php

    ReplyDelete
  10. Hi Arpit,
    I have created a macro and also name it as you have told, Now how to pull the password protect workbook.
    I tried file import->module-1 came up ->run the macro, but nothing happens

    Please advise

    ReplyDelete
  11. esoftTools - Make use of eSoftTools Excel password cracker program for cracking Excel file password and recovering Excel password with xls, xlsx, xltm, xla, xlm, xlam, xlsm and xlsb Read More:http://www.esofttools.com/excel-password-recovery.htmla

    ReplyDelete
  12. PDS Excel Password Cracker Software that instantly crack excel file protecton password and break excel sheet protection password. This program easily recover forgotten MS Excel file password and also gives demo facility to recover password of first three character of show the password.

    Click Here: http://www.excelpasswordcracker.com/

    ReplyDelete
  13. Superb Macro, it really saved me
    Thank you so much

    ReplyDelete
  14. I want to thank the friend who shared this code. It was and still is of great value.

    ReplyDelete