Closed Thread
Results 1 to 9 of 9

VBA to open a password protected workbook

  1. #1
    Forum Contributor
    Join Date
    01-28-2008
    MS-Off Ver
    Excel 365
    Posts
    157

    VBA to open a password protected workbook

    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)

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: VBA to open a password protected workbook

    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
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    bugmenot
    Guest
    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

  4. #4
    Registered User
    Join Date
    05-08-2008
    Posts
    35
    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?

  5. #5
    Registered User
    Join Date
    05-08-2008
    Posts
    35
    I actually just figured it out:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon Larry.LeBlanc@O
    Quote Originally Posted by mattydalton View Post
    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
    Please familiarise yourself with the rules before posting. You can find them here.

  7. #7
    Registered User
    Join Date
    11-07-2016
    Location
    India
    MS-Off Ver
    MS office 2010
    Posts
    5

    Re: VBA to open a password protected workbook

    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

  8. #8
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to open a password protected workbook

    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.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,647

    Re: VBA to open a password protected workbook

    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.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1