VB Code to Open Password Protected Excel File

pliskers

Active Member
Joined
Sep 26, 2002
Messages
394
Office Version
2016
Platform
Windows
Is there VB code to include the entry of a password to open a password protected Excel file? I tried recording the steps but the code that was recorded only showed the File-Open step without any reference to the fact that the password was entered.

Thanks in advance!
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Workbooks.Open "Path\Filename.xls", Password:="Jon", WriteResPassword:="Fred"

There are 2 possible passwords
Password is for Open
WriteResPassword is for Modify
 

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
Code:
Workbooks.Open Filename:= "C:\johndoe.xls", Password:="Password"
 

pliskers

Active Member
Joined
Sep 26, 2002
Messages
394
Office Version
2016
Platform
Windows
Awesome! Thanks for the quick reply!
 

pliskers

Active Member
Joined
Sep 26, 2002
Messages
394
Office Version
2016
Platform
Windows
A follow up question: What would be the code to save a file with a specific password?

Thanks again!
 

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
Code:
ActiveWorkbook.SaveAs "C:\johndoe.xls", Password:="Password"
Dom
 

Watch MrExcel Video

Forum statistics

Threads
1,090,103
Messages
5,412,444
Members
403,427
Latest member
mese0115

This Week's Hot Topics

Top