Entering password for protected WB

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
243
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I'm using the following code to open a workbook.

VBA Code:
Workbooks.Open (fPath & fName)

fPath & fName are, of course, specified before hand but I've omitted that for simplicity.

The workbook being opened, however, is password protected (which, when running the code, it asks for after reaching the above line). Unfortunately I'm a little stumped on how to actually enter the password using VBA (instead of entering manually). This isn't usually a problem as
VBA Code:
Workbooks("Book1").Unprotect "password"
usually works.

But in my case it doesn't seem to play nicely with the fPath & fName method of opening a file (which I must use for other reasons unfortunately). Screen updating is also off if that makes any difference.

Thanks for the help!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,
if you mean the workbook is password protected to open? then try

VBA Code:
Workbooks.Open fpath & fname, Password:="password"

Dave
 
Upvote 0
Solution
Thanks you two, I'd completely forgotten this method..

VBA Code:
Workbooks.Open fpath & fname, Password:="password"

Figured it out almost as soon as I posted the question lol, sorry for taking up your time!
 
Upvote 0
No worries glad we could help
We appreciate the feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,213,485
Messages
6,113,931
Members
448,533
Latest member
thietbibeboiwasaco

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