VBA创建受密码保护的文件 [英] VBA to create password protected file

查看:64
本文介绍了VBA创建受密码保护的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码,我可以创建受密码保护的文件的副本.但我也想将密码放在新创建的文件中.创建新的Excel工作簿时如何添加密码.

With the below coding, I am able to create a copy of password protected file. But I also want to put the password in newly created file. How can I add password while creating new excel workbook.

Workbooks.Open Filename:=myFileNameDir, Password:="yourpassword", UpdateLinks:=0
Set ws1 = Worksheets("OJT Plan")
ws1.Activate
filen = TextBox3.Text & "_" & TextBox59 & "_" & VBA.Format(Now, "MMddyyyyhmmss AM/PM ")
ws1.SaveAs Sheet1.Range("V3").Value & filen & ".xlsx"
Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "Details"
Set ws13 = Worksheets("Details")

推荐答案

如果您查看文档,您将看到 SaveAs 命令

If you look at the documentation you will see there are two password arguments for the SaveAs command

ws1.SaveAs FileName:=Sheet1.Range("V3").Value & filen & ".xlsx", _
           Password:="yourpassword", _                                
           WriteResPassword:="yourreadonlypassword"

这两个密码参数的区别在文档中进行了解释:

The difference in these two password arguments is explained in the docs:

密码 :区分大小写的字符串(不超过15个字符),指示要提供给文件的保护密码.

Password: A case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.

WriteResPassword :一个字符串,指示该文件的写保留密码.如果使用密码保存了文件,并且在打开文件时未提供密码,则该文件将以只读方式打开.

WriteResPassword: A string that indicates the write-reservation password for this file. If a file is saved with the password and the password isn't supplied when the file is opened, the file is opened as read-only.

这篇关于VBA创建受密码保护的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆