Excel uses VBA to crack a worksheet/workbook password

Source: Internet
Author: User
Tags exit chr goto password protection

Download the workbook online, found that there is a password!xxoo, since put on the Internet why to add a password ah?! Later on the internet to find a way to use VBA to crack the worksheet password, to share.

First, when you try to open the workbook, you are prompted with a password:

Using the shortcut key ctrl+f11, open the VBA editing interface and tap the submenu "module" under the "Insert" menu:

Enter the following code in the module editor:

Option Explicit

Public Sub allinternalpasswords ()

Const Dblspace as String = vbnewline & vbNewLine

Const AUTHORS as String = Dblspace & vbNewLine & _

"Adapted from Bob McCormick base code by" & _

"Norman Harker and JE McGimpsey"

Const HEADER as String = "allinternalpasswords User message"

Const VERSION as String = Dblspace

Const Repback as String = dblspace & "Please failure" & _

"to the microsoft.public.Excel.programming newsgroup."

Const AllClear as String = Dblspace & "The workbook should" & _

"Now is free of all password protection, so make sure to you:" & _

Dblspace & "SAVE IT now!" & Dblspace & "and also" & _

Dblspace & "backup!, backup!!, Backup!!!" & _

Dblspace & "Also, remember that password is" & _

"Put there for a reason." Don ' t stuff up crucial formulas "& _

"or data." & Dblspace & "Access and use of some data" & _

The May is an offense. If in doubt, Don ' t. "

Const MSGNOPWORDS1 as String = "There were no passwords on" & _

"Sheets, or workbook structure or Windows." & AUTHORS & VERSION

Const MSGNOPWORDS2 as String = "There is no protection to" & _

"Workbook structure or Windows." & Dblspace & _

"Proceeding to unprotect Sheets." & AUTHORS & VERSION

Const msgtaketime as String = "After pressing OK button This" & _

"would take some time." & Dblspace & "Amount of Time" & _

"Depends on how many different passwords," & _

"Passwords, and your computer ' s specification." & Dblspace & _

"Just be patient! Make me a coffee! "& AUTHORS & VERSION

Const MSGPWORDFOUND1 as String = "You had a worksheet" & _

"Structure or Windows Password set." & Dblspace & _

"The password found was:" & Dblspace & "$$" & Dblspace & _

"Note that it down for potential future use in the other workbooks by" & _

"The same person who set this password." & Dblspace & _

"Now to check and clear passwords." & AUTHORS & VERSION

Const MSGPWORDFOUND2 as String = "You had a worksheet" & _

"Password set." & Dblspace & "The password found was:" & _

Dblspace & "$$" & Dblspace & "Note it down for potential" & _

"Future use in the other workbooks by same who" & _

' Set this password. ' & Dblspace & ' Now to check and clear ' & _

"Other passwords." & AUTHORS & VERSION

Const Msgonlyone as String = "Only Structure/windows" & _

"Protected with the password", just found. "& _

AllClear & AUTHORS & VERSION & Repback

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 With

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

MsgBox MSGNOPWORDS2, vbinformation, HEADER

Else

On Error Resume Next

Do ' dummy Do loop

For i = the 66:for j = to 66:for K = 66

For L = 66:for m = 66:for to I1 = 66

For i2 = 66:for i3 = 66:for I4 = 66

For i5 = 66:for I6 = 66:for n = $ 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 With

Next:Next:Next:Next:Next:Next

Next:Next: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 = the 66:for j = to 66:for K = 66

For L = 66:for m = 66:for to I1 = 66

For i2 = 66:for i3 = 66:for I4 = 66

For i5 = 66:for I6 = 66:for n = $ 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:Next:Next

Next:Next:Next:Next:Next:Next

Loop Until True

On Error GoTo 0

End If

End With

Next W1

End If

MsgBox AllClear & AUTHORS & VERSION & Repback, vbinformation, HEADER

End Sub

Click to run:

The crack process takes several minutes, several dialog boxes pop up, all in English, and note the following in the dialog box:

The callout section is a password. This is not the original password, but you can still open the workbook with this password.

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.