[英]How to save a file with password in UFT
我正在使用UFT 12.5。 在运行时,它将打开excel和word。 然后,它在两个文件中写入一些数据。 之后,我想用新名称保存两个文件,然后用密码保护。 我需要能够手动输入密码才能打开它。 到目前为止,我已经编写了以下代码,最后一行出现错误。
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs mm1, "ttt"
请告知我如何使用UFT使用密码保存word和excel文件。
谢谢。
您需要使用SaveAs
方法传递正确的参数。 检查this
链接以获取更多信息。
这是您可以尝试的工作代码:
file = "File path with file name"
newfile = "File path with new file name"
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs newfile, , "test"
ExcelFile.Close
ExcelObj.Quit
UPDATE
根据OP的评论
如果要使用ReadOnly
保存文件,则必须通过以下方式使用WriteResPassword
参数:
ExcelFile.SaveAs newfile, , , "test"
请注意,我分别为
FileFormat
和Password
有两个空参数。这样,它将要求输入密码以写模式打开文件,如果您不提供密码,则文件将以
ReadOnly
模式打开。
检查我提到的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.