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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

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,095,415
Messages
5,444,338
Members
405,278
Latest member
karen1

This Week's Hot Topics

Top