Someone gave me a bit of VBA code which is supposed to get rid of some password protection I put on an Excel document which I now cannot open. I wonder if anyone could confirm that this is what it does and not something unscrupulous (like hack all my passwords!)
The VBA code is;
Sub PasswordBreaker()
Dim i As Integer, i1 As Integer, i2 As Integer, i3 As Integer, _
i4 As Integer, i5 As Integer, i6 As Integer, i7 As Integer, _
i8 As Integer, i9 As Integer, i10 As Integer, i11 As Integer, _
unusedVar As VbMsgBoxResult, passLine As String
On Error Resume Next
For i = 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 i7 = 65 To 66: For i8 = 65 To 66:
For i9 = 65 To 66: For i10 = 65 To 66: For i11 = 32 To 126:
passLine = Chr(i) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & _
Chr(i5) & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & _
Chr(i10) & Chr(i11)
ActiveSheet.Unprotect passLine
If ActiveSheet.ProtectContents = False Then
unusedVar = MsgBox("Password cracked at random string: " & _
passLine & vbCrLf & "|xxxxx[;;;;;;;;;>", _
vbOKOnly, "VBA Brute")
Exit Sub
End If
Next: Next: Next: Next: Next: Next:
Next: Next: Next: Next: Next: Next:
End Sub
Thanks
EDIT-
More for anyone else interested than to get the 'too broad' question re-opened, I've spent the last day reading up on VBA code instructions and I think I've got somewhere with what this does.
The first bit just defines what type of variable all the i...i11 are going to be (Integers) and the variable 'passline' is going to be a text string.
The third bit creates the variable 'passline' out of characters somehow made up by using all the variables i...i11 (I suspect Chr and then a number represents a specific keyboard entry).
ActiveSheet.Unprotect passline obviously instructs Excel to unlock the active sheet using the variable 'passline'.
The next bit seems to be checking to see if the sheet has been unprotected and if it has, shows the message box with what seems to be the 'passline' variable, some text, an "OK" button and a title.
Then if the sheet has not been unprotected, all the 'Next' functions somehow make it try again, exiting only when it's done it.
The bits that I'm still unsure about are;
Why 'On Error Resume Next' - Why would it be an Error?
Why is the unusedVar defined as the message box result, surely that can only be a 1/0 type of variable since the message box result is just whether the "OK" button has been pressed? I don't get what this has to do an unused Variable. And how come the unused variable itself equals (=) a message box later on? Why isn't is just IF (the password has been cracked), THEN (show the message box)?
Finally, why 12 Nexts, does it really only take twelve attempts to crack the password (one per character?)?
Obviously these questions will probably remain unanswered now, but as this question comes up as the top result in Google for anyone searching this particular code, and most of the community here seems to be more interested in making snide remarks than actually helping, I thought I'd at least share what I've found out. I appreciate the one answer I did get, but I thought breaking the code down step by step might give others a bit more reassurance than just a summary of what it does.
Of course as this question was 'too broad' I doubt anyone will have been able to make to the end of such a massively protracted explanation.