Permission & Access Issues

Open a Password-Protected Word Document with Excel VBA

Jason MillerJason Miller Nov 27, 2026 869 views

Question details

Open a password-protected Word document from an Excel VBA macro using the known document password.

Open a Password-Protected Word Document with Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11 to open the Visual Basic Editor.

2
Add the Word reference

Select Tools > References, check Microsoft Word 14.0 Object Library, and click OK.

3
Add the macro

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

4
Run the macro

Click inside the macro and press F5. Word should open the document if the path and password are correct.

Pass the document password to Word's Documents.Open method
Protect the password: A password written directly in VBA code may be visible to others who can access the workbook or its code. Use an appropriate secure method to obtain it instead of hard-coding it in shared files.
Free Microsoft Office alternative

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.

Open and edit password-protected documents when you know the passwordWork with Microsoft Word DOCX and Excel XLSX formatsUse familiar document and spreadsheet toolsMove everyday Office files into a lightweight, free suite
microsoft office alternative - wps 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.