How to open another workbook that is password protected?

Chris Williamson

Board Regular
Joined
Oct 16, 2010
Messages
83
Hi,

Code:
Sub Open_Test_File()
    Dim wb As Workbook
    Set wb = Application.Workbooks.Open("Desktop\Test File.xls")
End Sub

This very simple little code opens a new workbook.

But if I add a password to the file that I'm going to open the password box appears.

What do I need to add to this code to automatically input this password?

I have tried putting this at the end:
Code:
Password:="123"
but this does not work?

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This should work

Code:
    Set wb = Application.Workbooks.Open(Filename:="Desktop\Test File.xls", Password:="123")
 
Upvote 0
Thank you,

I had the Password:="123" outside the end bracket<!-- / message --><!-- sig -->

Code:
Set wb = Application.Workbooks.Open(Filename:="Desktop\Test File.xls")Password:="123"
<!-- / message --><!-- sig -->
 
Upvote 0

Forum statistics

Threads
1,202,958
Messages
6,052,791
Members
444,602
Latest member
Cookaa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top