SaveAs密码保护文档没有密码 - Excel VBA

时间:2017-03-30 13:14:26

标签: vba excel-vba excel

我在Excel中使用下面的宏打开受密码保护的Word文档,然后我想保存没有密码保护的文档副本。目前,当我尝试打开新保存的文档时,仍然会提示我输入原始密码。

Dim DPObj
Dim DPApp As Object
Dim YourOwnPassword As String
Dim DocPath As String
DocSrcPath = "C:\Users\ADMIN\Desktop\Sources\SourceDoc.doc"
DocTgtPath = "C:\Users\ADMIN\Desktop\Targets\TargetDoc.doc"
YourOwnPassword = "TestPWD"
Set DPApp = CreateObject("word.Application")
'Open Password enabled document
DPDoc = DPApp.Documents.Open(DocSrcPath, PasswordDocument:=YourOwnPassword)
'Make some changes to the document. 
'Save the edited document without a password
DPApp.ActiveDocument.SaveAs2 DocTgtPath

有人知道怎么做才能让TargetDoc.doc仍受密码保护吗?

1 个答案:

答案 0 :(得分:2)

使用空白密码应该有效:

DPApp.ActiveDocument.SaveAs2 DocTgtPath, Password:=""