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