vba to open enripted password excel file

Please see the attached excel. I went to options > encrypt with password. Then in VBA I try to open the file using this code:
Set wkb = objXL.Workbooks.Open(mypathFile, , , , password:="password", WriteResPassword:="password")
But it says incorrect password, error 1004. Can you please help gurus

Thanks
withEncriptedPassword.xlsx
encrotionpasswordHow.jpg
RayneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
There several, free, password retriever's for Excel on the web.
0
RayneAuthor Commented:
U don't to retrieve any password ...since I know the password ......my question is how in vba code I can open that file ....
0
RayneAuthor Commented:
The password is password
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Martin LissOlder than dirtCommented:
I think you had the password parameter in the wrong place. This works. Don't forget to change C:\temp to match your path.

Set wkb = Workbooks.Open("C:\temp\withEncriptedPassword.xlsx", , , , "password", "password")
0
RayneAuthor Commented:
0
RayneAuthor Commented:
i am using access vba to open this excel file just FYI
0
RayneAuthor Commented:
so your code is not working i got the issue
0
Martin LissOlder than dirtCommented:
What method did you use to password protect the workbook? I created a workbook and saved it with a password by way of the File->Save As->Tools->General Options and when I did that I was able to open it with this code in Access.

I attached my workbook.


Dim objXL As New Excel.Application
Dim wkb As Excel.Workbook
objXL.Visible = True
Set wkb = objXL.Workbooks.Open("C:\temp\MyWorkbook.xlsx", Password:="password")

Open in new window

MyWorkbook.xlsx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RayneAuthor Commented:
Martin is my HERO :)
0
RayneAuthor Commented:
thank you
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

For my own interest can you tell me what the problem was?

Marty - MVP 2009 to 2015
0
RayneAuthor Commented:
could be two things - using one comma instead of four like this:
withEncriptedPassword.xlsx", , , , "password",


another - i was storing the password in a variable and using the variable in the last code you gave
0
Martin LissOlder than dirtCommented:
Are you asking for more help? If so then please explain what you need.
0
RayneAuthor Commented:
Martin  i am not asking any help. I tried to answer your last question as to what resolved the issue :)
0
Martin LissOlder than dirtCommented:
Sorry, I forgot I asked you that:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.