Use VBA to Open a Password-Protected File

srdavisgb

Board Regular
Joined
Nov 5, 2011
Messages
51
I am trying to use a macro to consolidate data from protected workbooks. Note: It appears PowerQuery doesn't like password-protected files.


Below is the vba I have used to open unprotected files in the past. How do I modify the script to provide the required password.


Code:
[/COLOR]Workbooks.Open Filename:=GetMasterDataInputPath & "\" & Filename[COLOR=#574123][CODE][/COLOR]




I tried to add the password object but, it appears I need and end statement.


[COLOR=#574123][CODE][/COLOR]Workbooks.Open Filename:=GetMasterDataInputPath & "\" & Filename _Password:=PSWD[COLOR=#574123][CODE][/COLOR]


[COLOR=#ff0000][B]Your suggestions/solutions are greatly appreciated![/B][/COLOR]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Code:
Sub Open_Unlock()

'Unlock Password Protected File using both an Open Password and a Modify Password
Workbooks.Open "C:\Users\YourPath\Desktop\Sheet1.xlsm", Password:="apple", WriteResPassword:="apple", ReadOnly:=False




'Unlock Password Protected File just an Open Password
Workbooks.Open "C:\Users\YourPath\Desktop\Sheet1.xlsm", Password:="apple", ReadOnly:=False


'Unlock password protected Workbook to Modify
ActiveWorkbook.Unprotect Password:="apple"


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,113
Messages
6,189,045
Members
453,521
Latest member
Chris_Hed

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