Remove password from an Excel Document

11

6

I'm providing internal support and one of our users has managed to put a password on an excel file by accident, I've done the proper checks to make sure that the user should have access to the document and now want to know what the recommendation for removing a password from an Excel document.

For what its worth, the password appears after Excel opens but before you can see any data in excel.

Ben Confino

Posted 2009-10-21T09:26:59.523

Reputation:

the excel .xlsx file is actually just a zip file. unzip and follow instructions such as these. have tried in past not sure if it works if whole file is password protected though. http://nileshkumar83.blogspot.com/2012/05/breaking-excel-password-protection.html

– Joop – 2014-10-01T12:41:39.983

1

@SamuelJaeschke The hook method at https://stackoverflow.com/a/27508116/5757159 works every time. No cracking required.

– ThunderFrame – 2017-07-26T06:47:28.987

Um, you're kinda stuffed. Unless you want to do complicated cryptography stuff... (I'm not aware of any programs for doing this on .xls). There's no normal, automated way of doing this in Excel - that would kind-of defeat the point of having a password in the first place... your only hope would be a special cipher cracking program for such files (which may be hard to find). Maybe Google decrypt xls or something similar. – Samuel Jaeschke – 2009-10-21T10:06:32.313

Answers

11

Elcomsoft make a pretty useful program called Advanced Office Password Recovery which can do the job better than anything else I've used.

It's probably worth putting a value on the data you're trying to recover before attempting this, sometimes it's less expensive to let the user re-create the document from scratch (and teaches them a valuable lesson ;-) ). AOPR isn't free, and the passwords can sometimes only be worked out by brute force (trying every possible combination of letters) which can take a very long time.

Mike1980

Posted 2009-10-21T09:26:59.523

Reputation: 650

I'm not a fan of recommending commercial software on this site, but in this case it's by far the best choice. Recommended. +1. – agtoever – 2014-11-10T12:57:30.370

Elmcomsoft's programs are good, I've had success with this in the past for opening an Excel file I was sent without the password. Get a decent wordlist, and try that first (the one included in Cain and Abel is a nice 3MB one). If that fails, give brute force a try, but if it's a strong password, you're never getting in. – Dentrasi – 2009-10-21T18:58:19.280

1

If you know what the password is, go ahead and open the Excel document. Then click on File > Save As. To the left of the Save button is a little drop down labeled Tools. Click on that, and then click on General Options. Delete the password entries there, and click OK. Save the document.

If you do not know what the password is, you can use VBA to find it. If I had to take a guess, your user probably didn't use a super strong password, so we could use a brute force type method to find it. The code below is rough, but it has helped me find a weak, lost password on several of my users' documents. It checks for passwords of any length with the ASCII characters from 1 to z. You would call it from the Immediate Window and wait several minutes like so:

? GetPassword("D:\mywkbk.xlsx")

-

Public Function GetPassword(ByRef sFileName As String) As String
On Error Resume Next
    Dim pw As String
    pw = ""
    Do
        VBA.Err.Clear
        pw = GenerateNextPassword(pw)            
        Application.Workbooks.Open sFileName, False, True, , pw, pw
        VBA.DoEvents
    Loop While VBA.Err.Number = 5408
    GetPassword = pw
End Function

Public Function GenerateNextPassword(ByRef sCurrentPassword As String) As String
    Const MAX_CHAR = 122
    Const MIN_CHAR = 49

    Dim sCurrentPasswordMax As String
    Dim sNewPassword As String
    Dim i As Long

    sCurrentPasswordMax = String(Len(sCurrentPassword), Chr(MAX_CHAR))
    If sCurrentPassword = sCurrentPasswordMax Then
        'do an increment that changes the length
        sNewPassword = String(Len(sCurrentPassword) + 1, Chr(MIN_CHAR))
        Debug.Print Now(); ": "; sNewPassword
    ElseIf Asc(Right(sCurrentPassword, 1)) = MAX_CHAR Then
        'do an increment that changes multiple characters
        sNewPassword = Left(sCurrentPassword, Len(sCurrentPassword) - 1) & Chr(MIN_CHAR)
        For i = Len(sCurrentPassword) - 1 To 1 Step -1
            sNewPassword = Left(sNewPassword, i - 1) & Chr(Asc(Mid(sNewPassword, i, 1)) + 1) & Mid(sNewPassword, i + 1)
            If Asc(Mid(sCurrentPassword, i, 1)) <> MAX_CHAR Then
                Exit For
            End If
        Next i
    Else
        'do an increment on the rightmost character
        sNewPassword = Left(sCurrentPassword, Len(sCurrentPassword) - 1) & Chr(Asc(Right(sCurrentPassword, 1)) + 1)
    End If

    GenerateNextPassword = sNewPassword
End Function

Bobort

Posted 2009-10-21T09:26:59.523

Reputation: 190

It's implicit that the password has been lost and forgotten, so your first paragraph is irrelevant. If you find your VBA routine to remove an unknown password, please let us know, but I suspect that it is impossible. – Scott – 2017-03-10T15:52:46.507

1After re-reading the OP, I would strongly argue that it is not clear that the password has been lost, so I keep that first paragraph there. I did update the answer with some VBA code that could be used to find the password within a few minutes or longer if the password is not known. – Bobort – 2017-05-10T18:46:08.583

1

Is something like this, the Excel Password Remover XLA add-in, what you are after?

EDIT: Thinking about it, maybe not - this is used for removing the password from protected worksheets/workbooks.

Bonus

Posted 2009-10-21T09:26:59.523

Reputation: 1 192

whether ethically we can solve using this tool ? – joe – 2009-10-21T10:41:18.640

0

The Hook approach demonstrated in this SO article works EVERY time.

https://stackoverflow.com/a/27508116/5757159

No Hex editors, no downloads, no installers. Just a pure VBA solution.

ThunderFrame

Posted 2009-10-21T09:26:59.523

Reputation: 1 015