# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  VBA to open a password protected workbook

## Larry.LeBlanc@O

How can I use vba to open an Excel workbook that has passwords for both opening and for modifying? I think this is close:

Workbooks.Open "Full Path Name",  Password: ="XYZ"

However, using that prompts me for a second password (to modify the workbook)

----------


## stanleydgromjr

Larry.LeBlanc@O,

You could record a macro from a blank workbook, and open the password protected workbook, and enter the password.  Then stop the macro recorder.

Then check the newly recorded macro for the code.


Have a great day,
Stan

----------


## bugmenot

Hi Larry,

Try something along these lines. Replace "Filename" with the file path you are tryinf to open and "Password" with the password required to open it.



```
Please Login or Register  to view this content.
```


Cheers

----------


## mattydalton

I am attempting to do exactly the same thing and, when I use the sample codes given here I am still getting the box asking for the password for modify access. Any other ideas?

----------


## mattydalton

I actually just figured it out:




```
Please Login or Register  to view this content.
```

----------


## dominicb

Good afternoon Larry.LeBlanc@O




> I am attempting to do exactly the same thing and, when I use the sample codes given here I am still getting the box asking for the password for modify access. Any other ideas?



The reason for this is that the user specified a file open password and a file modify password when the file was saved.  The code below will handle both types of password :



```
Please Login or Register  to view this content.
```


HTH

DominicB

----------


## Hemant Agarwal

I am looking to get code to open a protected excel file for which I lost the password to open, when I tried the above coding it is giving me "Run Time error 1004: The password you supplied is not correct Verify that the caps lock key is off and be sure to use the correct capitalization"

Please help me with VBA code to open a protected excel file which is password protected (to open and to modify)
thanks

----------


## cytop

Please read the board rules:
*2. Don't post a question in the thread of another member -- start your own*.
*11. Don't post questions regarding breaking or bypassing any security measure*

If you don't have the password then the question will not be answered.

----------


## AliGW

Unfortunately _your post does not comply with Rule 2 of our Forum_ RULES. *Do not post a question in the thread of another member -- start your own thread.* 

If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread. 

Old threads are often only monitored by the original participants.  New threads not only open you up to all possible participants again, they typically get faster response, too.

----------

