Noble
Noble

Reputation: 191

Excel VBA still prompts for password even after coded the password

This is an example of my code.

Set book = app.Workbooks.Open(wb.Path + "/" + Excel_Name, , , , "r@w51mt35t")

Although I have stated the password to open the password protected excel file, it stills prompt me to input the password for that protected excel file.

Just to be clear, I am trying to open another excel file from a macro of a currently active workbook. I have searched through internet and seems like no one had the same problem as me.

Note: The password protected excel file was created by me as well using the following code below.

wb.SaveAs wb.path & "\" + thirdtitle + "- TestPad", FileFormat:=51, Password:="r@w51mt35t"

Thanks!

Upvotes: 2

Views: 2554

Answers (1)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19067

I think when saving with password protection you set 2 level protection for both opening and changing. If so you need to do the following:

Set book = app.Workbooks.Open(wb.Path + "/" + Excel_Name, , , , "r@w51mt35t", "r@w51mt35t")

as the next argument is responsible for next level of protection. Of course, check the password if both are set the same.

Upvotes: 3

Related Questions