在VBA

时间:2016-05-31 15:44:37

标签: excel vba excel-vba ms-word word-vba

我需要在VBA中打开受密码保护的Word文档 它要求输入密码,如何通过代码打开 代码:

Dim DPDoc
Dim DPApp
Dim DPPath
DPPath = "C:\MyFolder\PwdProtectdFile.docx"
Set DPApp = CreateObject("word.Application")
' It is asking for the password here 
DPDoc = DPApp.Documents.Open(DPPath)

1 个答案:

答案 0 :(得分:3)

只需添加一个参数:

Dim YourOwnPassword As String
YourOwnPassword = "TestPWD"
DPDoc = DPApp.Documents.Open(DPPath, PasswordDocument:=YourOwnPassword)

Src:https://msdn.microsoft.com/en-en/library/office/ff835182.aspx