If you forget the password for your Excel file, you won’t be able to extract data from it or make new inputs. However, there are a few ways to retrieve the password.
Excel File Encryption Types
You can encrypt the Excel workbook with a password. This encryption requires passwords to open or view the file.
If you open the encrypted file, Excel will display a Password window to input the password to open or view it.
On the other hand, file encryption with Protect Sheet protects only a singular worksheet. In that case, the user needs to enter his/her password to edit or modify the worksheet.
In this article, we focus on the file encryption with Protect Sheet and demonstrate VBA Macro to recover encrypted file passwords. If users open the password-protected sheet, Excel displays a disclaimer, stating the file is a protected file and the user needs to input a password to edit or modify as depicted in the below image.
Method 1 – Applying VBA Macro to Recover an Excel File Password
The code tries iterations of probable passwords and generates a workable password to unprotect the worksheet.
This method works if the encrypted file is saved as the Excel 97-2003 Workbook(*xls) type as shown in the following picture.
Steps:
- Use Alt + F11 or go to the Developer tab and click on Visual Basic (in the Code section).
- The Microsoft Visual Basic window opens. Select Insert and click on Module.
- Paste the following macro in the Module.
Sub RecoverExcelFilePassword()
Dim u As Integer, v As Integer, w As Integer
Dim x As Integer, y As Integer, z As Integer
Dim u1 As Integer, u2 As Integer, u3 As Integer
Dim u4 As Integer, u5 As Integer, u6 As Integer
On Error Resume Next
For u = 65 To 66: For v = 65 To 66: For w = 65 To 66
For x = 65 To 66: For y = 65 To 66: For u1 = 65 To 66
For u2 = 65 To 66: For u3 = 65 To 66: For u4 = 65 To 66
For u5 = 65 To 66: For u6 = 65 To 66: For z = 32 To 126
ActiveSheet.Unprotect Chr(u) & Chr(v) & Chr(w) & _
Chr(x) & Chr(y) & Chr(u1) & Chr(u2) & Chr(u3) & _
Chr(u4) & Chr(u5) & Chr(u6) & Chr(z)
If ActiveSheet.ProtectContents = False Then
MsgBox "Can use this Password: " & Chr(u) & Chr(v) & _
Chr(w) & Chr(x) & Chr(y) & Chr(u1) & Chr(u2) & _
Chr(u3) & Chr(u4) & Chr(u5) & Chr(u6) & Chr(z)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub
The macro generates iterations of probable passwords and uses them to break the protection.
- Press the F5 key to run the macro. The macro takes quite some time to finish and returns an alternative password to unprotect the Worksheet.
⧭ Warning: Executing the macro may cause freezing or lagging. Refrain from running other memory- and CPU-intensive programs while running the code.
Method 2 – Removing Excel File Password Using the Zip Tool
Steps:
- In the device directory, select the encrypted file, and go to View in the Files Manager ribbon.
- Check File name extensions. File Explorer will show the file types (i.e., xlsx).
- Modify the File Extension to .zip.
- You’ll get a confirmation window, so click on Yes.
- The file gets converted into a zip file.
- Double-click on it.
- Double-click on the folder named xl.
- The xl folder holds the protected sheet or sheets. In this case, sheet1.xml is the zipped version of the encrypted Excel file. Copy the file to the Desktop or any location.
- Open the file using Notepad.
- Use Ctrl + F to bring out the Find window.
- Type in protect then click on Find Next in the window.
- Notepad highlights the “protect” text within the file text.
- Delete the entire <sheetProtect…..SelectUnlockedCells=”1”/> portion from file text.
- Save the file using File and going to Save.
- Copy and Replace the newly saved sheet1.xml file into the zip.
- Change the File Extension from zip back to xlsx.
- Open the modified xlsx file and you should be able to edit this version of the file.
Read More: How to Remove Password from Excel File
Download the Excel Workbook
Related Articles
<< Go Back to Unprotect Workbook in Excel | How to Unprotect in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!
Once I try to open the zipped file, I keep getting a Windows cannot open folder error
Hello BERNARD
Thanks for reaching out and posting your observation. The ZIP Tool method mentioned in the article can be applicable If you have a protected sheet within a workbook.
I have experienced the same error when the workbook is encrypted with a Password. But, if only a sheet is protected, the ZIP Tool works perfectly. When you preserve your workbook with an Encrypted Password, the ZIP Tool method will not work. So, use the VBA code to remove the password from the encrypted workbook. Good luck.
Regards
Lutfor Rahman Shimanto
ExcelDemy
the file open with box showing password. does not allow to open macros.
Hello JITHU
Thanks for reaching out. You are right about the file not allowing the opening of macros. The password is recovered using the Zip Tool, which will not let you open macros. In the article, the writer has demonstrated the file as a macro-free file when using the Zip tool. That’s why when changing back to the file type Zip to Excel, the .xlsx is used.
If you are working on a macro-enabled file when recovering a password using Zip Tool, change the file’s extension (when changing the file type Zip to Excel) to .xlsm instead of .xlsx.
Regards
Lutfor Rahman Shimanto
ExcelDemy