在VBA中打开受密码保护的Word文档

我需要在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) 

只需添加一个参数:

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

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