Open workbook with password in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have saved several workbooks in a directory that are password protected.
Using the following code, How do I tell it to use the password when it opens
the file?
MyPath is the directory path
MyFiles(Fnum) is the workbook name. This is an array of workbook names all
using the same password.

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))

Thanks
Shawn G.
 
Try this...

Set mybook = Workbooks.Open(Filename:=MyPath & MyFiles(Fnum), _
Password:="MyPassword")
 
Back
Top