简体   繁体   English

VBA密码保护Excel工作簿,无需保存

[英]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)? 是否可以使用Excel密码保护打开的Excel工作簿,而无需使用SaveAs方法(不使用任何方法来保存文件)?

Currently in our application, we use the SaveAs method to save and set the password after a workbook is generated and filled with data. 当前在我们的应用程序中,在生成工作簿并填充数据后,我们使用SaveAs方法保存和设置密码。 The generation of this workbook takes a while as we use a lot of data and the resulting file is quite big (120MB). 由于我们使用大量数据,因此生成此工作簿需要一些时间,因此生成的文件很大(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. 我们正在寻找加速工作簿生成的方法,并且发现SaveAs方法大约需要3分钟才能完成,因为需要计算大量公式。 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. 经过与用户的简短交谈,我们意识到每个人都对工作簿的UI进行了一些小的更改,因此他们需要再次保存并等待3分钟。

We have decided to suppress the SaveAs method and will be the users responsibility to save the workbook after they finish with their changes. 我们决定取消SaveAs方法,并且由用户负责在完成更改后保存工作簿。 And here is the problem, without the SaveAs I couldn't find a way to protect the file with a password. 这就是问题所在,没有SaveAs,我找不到用密码保护文件的方法。

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: 我尝试了Workbook.Protect,但似乎它只能保护结构和窗口不被更改,而不能保护文件不被打开:

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. 我还找到了Workbook.ProtectSharing方法,但是没有尝试过,因为文档说它保存了文件。

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. 您可以使用Workbook.Password属性,该属性是读/写的。 The password will be applied the next time the file is saved. 下次保存文件时将应用密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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