mjavon
mjavon

Reputation: 237

How to unprotect an Excel workbook

I have an Excel workbook that is password protected (the entire document, not just a sheet or set of sheets - you can't open the file without the password). I know the password, so I am able to open it, but there is no obvious way to turn off the password protection.

Specifically, I would like to do this in VBA, because eventually I want to be able to do this to multiple files using a loop. I tried using:

ThisWorkbook.Unprotect(Password = "[password]")

but this does absolutely nothing.

Upvotes: 3

Views: 8374

Answers (2)

Rory
Rory

Reputation: 34045

If it's the password to open the file, you want:

Thisworkbook.Password = ""

then save it.

Wb.Unprotect would remove the password that protects the workbook structure/windows.

Upvotes: 4

Chrismas007
Chrismas007

Reputation: 6105

Here is what the MSDN says

Sub Example()
    Dim WB as Workbook
    Dim pw as String

    Set WB = ThisWorkbook
    pw = "Your password"
    WB.Unprotect(pw)
End Sub

Upvotes: 3

Related Questions