If you are looking for ways to unprotect an Excel sheet without a password with the help of VBA, then you will find this article useful. Sometimes you may forget the password with which you have protected your sheet, and to solve this problem you can explore this article.
Unprotect Excel Sheet Without Password Using VBA: 3 Simple Steps
Here, we have the following dataset containing the records of sales and costs of some of the products of a company. But the sheet is protected with a password so we cannot make any changes here. To unprotect this sheet in the following steps we will show the ways to do this job easily with a VBA code.
We have used Microsoft Office 365 version here, you can use any other version according to your convenience.
Step-01: Opening Visual Basic Editor Window
Here, we have a sheet VBA where we have some records of the products. And we have protected it with a password.
So, for trying to make any changes we are getting the following message.
➤ To unprotect this sheet with the help of a VBA code right-click on the sheet name and then select the View Code option.
After that, the Visual Basic Editor window will open up.
Step-02: Typing VBA Code to Unprotect Excel Sheet without Password
➤ Type the following code
Sub unprotect_without_pass()
Dim digit1, digit2, digit3, digit4, digit5, digit6, _
digit7, digit8, digit9, digit10, digit11, digit12 As Integer
If ActiveSheet.ProtectContents Then
On Error Resume Next
For digit1 = 65 To 66: For digit2 = 65 To 66: For digit3 = 65 To 66
For digit4 = 65 To 66: For digit5 = 65 To 66: For digit6 = 65 To 66
For digit7 = 65 To 66: For digit8 = 65 To 66: For digit9 = 65 To 66
For digit10 = 65 To 66: For digit11 = 65 To 66: For digit12 = 32 To 126
ActiveSheet.Unprotect Chr(digit1) & Chr(digit2) & Chr(digit3) & _
Chr(digit4) & Chr(digit5) & Chr(digit6) & Chr(digit7) & Chr(digit8) & _
Chr(digit9) & Chr(digit10) & Chr(digit11) & Chr(digit12)
Next digit12: Next digit11: Next digit10: Next digit9: Next digit8: Next digit7
Next digit6: Next digit5: Next digit4: Next digit3: Next digit2: Next digit1
MsgBox "One usable password is " & Chr(digit1) & Chr(digit2) & _
Chr(digit3) & Chr(digit4) & Chr(digit5) & Chr(digit6) & Chr(digit7) & _
Chr(digit8) & Chr(digit9) & Chr(digit10) & Chr(digit11) & Chr(digit12)
End If
End Sub
Here, we have declared digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, digit10, digit11, and digit12 As Integer.
The IF-THEN statement will ensure if the sheet is protected or not and if it is protected then the following operation will continue. Then we have used 12 FOR-NEXT loops for assigning 12 ranges of values to our declared digits and these loops will work as nested loops to unprotect the sheet with the help of these digits and the CHR function will convert them to strings.
Finally, a message box (MsgBox) will appear with a randomly generated password with the help of this code.
Step-03: Running Code to Unprotect Excel Sheet without Password
➤ Press F5.
This code will take some time to run.
After that, the sheet will be unprotected with the following message box containing a randomly generated password.
So, we can easily change the values of this dataset and convert Strawberry to Orange here.
One thing is to remember that this code will require huge time to run. And so it is better to do this operation on a spare PC.
Similar Readings
- How to Unprotect Excel Sheet with Password Using VBA
- Excel VBA: Unprotect All Sheets
- How to Unprotect Excel Sheet with Password
- How to Unprotect Excel Sheet If Forgot Password
Practice Section
For doing practice by yourself we have provided a Practice section like below in a sheet named Practice. Please do it by yourself.
Download Workbook
Conclusion
In this article, we tried to cover the steps to unprotect an Excel sheet without a password with the help of VBA. Hope you will find it useful. If you have any suggestions or questions, feel free to share them in the comment section.