Excel: how to undo the worksheet password after you forget the password

Source: Internet
Author: User
Tags password protection

1. Open the Excel file that you want to cancel the password protection;

2. Click the tool --- macro on the menu bar to record the new macro and enter the macro name, for example, AB;

3. Stop recording (in this way, an empty macro is obtained );

4. Choose tools> macro from the menu bar, select AB, and click Edit;

5. Delete All characters (only a few characters) in the window and replace them with the following;

 

Public sub worksheet password protection ()
Const dblspace as string = vbnewline & vbnewline
Const authors as string = dblspace & vbnewline &_
"Author: Eric"
Const header as string = "worksheet password protection"
Const version as string = dblspace & "version 1.1.1"
Const repback as string = dblspace &""
Const Zhengli as string = dblspace & "Eric"
Const allclear as string = dblspace & "the worksheet password protection in this workbook has been completely removed. "& Dblspace &" Remember to reset the password "_
& Dblspace & "NOTE: This method is only used to forget passwords. "
Const msgnopwords1 as string = "this file worksheet is not encrypted"
Const msgnopwords2 as string = "this file worksheet is not encrypted 2"
Const msgtaketime as string = "please be patient! "& Dblspace &" reply by OK"
Const msgpwordfound1 as string = "password combination:" & dblspace & "$" & dblspace &_
"If the worksheet of this file has different passwords, search for the next set of passwords and modify and clear them"
Const msgpwordfound2 as string = "password combination:" & dblspace & "$" & dblspace &_
"If the worksheet of this file has different passwords, search for the next group of passwords and remove them"
Const msgonlyone as string = "Is it unique? "
Dim W1 as worksheet, W2 as Worksheet
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
Dim pword1 as string
Dim shtag as Boolean, wintag as Boolean
Application. screenupdating = false
With activeworkbook
Wintag =. protectstructure or. protectwindows
End
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
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
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
Loop until true
On Error goto 0
End if
End
Next W1
End if
Msgbox allclear & authors & version & repback & Zhengli, vbinformation, Header
End sub

 

6. Close the editing window;

7. Click the tool --- macro ----- macro on the menu bar, select allinternalpasswords, and run the tool twice. wait for a minute or two. The following dialog box is displayed:

This is the original password corresponding to the Excel password (both this password and the previously set password can open this document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.