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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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,222,194
Messages
6,164,508
Members
451,900
Latest member
lamski

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