udhaya kumar
udhaya kumar

Reputation: 63

Open a password protected Word document in VBA

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

Answers (1)

R3uK
R3uK

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

Related Questions