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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,216,729
Messages
6,132,385
Members
449,725
Latest member
Enero1

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