How to unprotect an Excel workbook

谁说我不能喝 提交于 2019-12-11 03:56:23

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/31297188/how-to-unprotect-an-excel-workbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!