Open a Password-Protected Word Document with Excel VBA
Question details
Open a password-protected Word document from an Excel VBA macro using the known document password.

- Product
- Microsoft Excel 2010 and Microsoft Word 2010
- Device & OS
- not provided
- Scenario
- An Excel VBA macro needs to open a Word document that requires a password.
- Observed behavior
- The Word Documents.Open method does not open the protected document as expected.
Confirm that Word 2010 is installed and that you know the document's opening password and full file path. The password argument does not bypass document protection.
Pass the document password to Word's Documents.Open method
Use Word automation from Excel VBA and supply the known opening password with the PasswordDocument argument.
In Excel, press Alt+F11 to open the Visual Basic Editor.
Select Tools > References, check Microsoft Word 14.0 Object Library, and click OK.
Select Insert > Module and paste this code, replacing the file path and password with your own: Sub OpenProtectedWordDocument() Dim wdApp As Word.Application Dim wdDoc As Word.Document Set wdApp = New Word.Application wdApp.Visible = True Set wdDoc = wdApp.Documents.Open( _ FileName:="C:\Path\Document.docx", _ PasswordDocument:="password") End Sub
Click inside the macro and press F5. Word should open the document if the path and password are correct.

Work with Word and Excel files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move everyday document and spreadsheet work. It does not fix Excel-to-Word VBA automation in Microsoft Office.

Frequently Asked Questions
Which VBA argument supplies the Word document password?
Pass the known opening password as PasswordDocument in Word's Documents.Open call, alongside the FileName argument.
Do I need to add a Word reference in Excel?
For the example using Word.Application and Word.Document, open the VBA editor and select Tools > References > Microsoft Word 14.0 Object Library.
Can this macro open a document if I don't know its password?
No. PasswordDocument supplies an existing password; it does not recover or bypass an unknown password.
What if the document still does not open?
Check the full path in FileName, verify the opening password in Word, and confirm that the Word object library is selected under Tools > References.




