简体   繁体   中英

VBA Password Protect Excel Workbook without Save

It is possible to password protect an excel workbook for opening without the use of SaveAs method (without any method to save the file)?

Currently in our application, we use the SaveAs method to save and set the password after a workbook is generated and filled with data. The generation of this workbook takes a while as we use a lot of data and the resulting file is quite big (120MB).

We were searching for some ways to accelerate the workbook generation and we found that the SaveAs method takes around 3 minutes to complete because a lot of formulas needs to be calculated. After a small talk with the users, we realize that everyone make some small changes to the UI of the workbook anyway so then they need to save again and wait for another 3 minutes.

We have decided to suppress the SaveAs method and will be the users responsibility to save the workbook after they finish with their changes. And here is the problem, without the SaveAs I couldn't find a way to protect the file with a password.

I have tried the Workbook.Protect but it seems it only protects the structure and the windows from changes but not the file from opening:

ActiveWorkbook.Protect Password:=cPwd, Structure:=True, Windows:=False

I also found the Workbook.ProtectSharing method but I did not tried because the documentation says that it saves the file.

So, is there any way to set a workbook password without saving the file that will be applied when the user save it manually after his changes?

You can use the Workbook.Password property, which is read/write. The password will be applied the next time the file is saved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM