Reputation: 63
I need to open the Password protected word document in VBA It is asking for the password, how to open via code Code:
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)
Upvotes: 1
Views: 9325
Reputation: 14537
Simply add an argument :
Dim YourOwnPassword As String
YourOwnPassword = "TestPWD"
DPDoc = DPApp.Documents.Open(DPPath, PasswordDocument:=YourOwnPassword)
Src : https://msdn.microsoft.com/en-en/library/office/ff835182.aspx
Upvotes: 3