1
votes

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)
1

1 Answers

3
votes

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