+ Reply to Thread
Results 1 to 3 of 3

Change password to open excel file programatically

  1. #1
    Registered User
    Join Date
    11-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Change password to open excel file programatically

    Hi

    I have an excel file which requires a password to open (no password needed to modify) - and it is my file, so I know the current password.

    Is it possible to write a macro which will change the password to the value specified in a particular cell e.g. cell A1?

    Many thanks.

  2. #2
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Change password to open excel file programatically

    One thing I can thing of, is to create a macro called up in Open event. The macro displays input box and ask the user to type a password. If the password matches whatever in cell A1 (for example) then the file open.
    aelgadi

    > Click Star if I helped. Thanks

  3. #3
    Registered User
    Join Date
    10-07-2012
    Location
    Richmond, VA USA
    MS-Off Ver
    2010
    Posts
    10

    Re: Change password to open excel file programatically

    If I understand your request properly, what you are looking for is a way to protect the file contents from being viewed (hence the password to open the file) but once that password is supplied, there will be no restrictions on modifying the file.

    If this is the case, you will likely need to use an approach something like the following:

    1) Setup your workbook to force the user to enable macros upon opening the workbook. See the article Force users to enable macros in a workbook by Ken Puls for one way in which to do this. There are probably several other viable alternatives to force enabling of macros out there.

    2) Modify the WorkbookOpen event such that when the user opens the workbook, your code displays an input box requesting the required password to open the file. If the correct password is supplied, have your code continue with the ShowAllSheets subroutine (referenced in Ken Puls method).

    3) Once the password is validated, continue with the remainder of the process for unhiding the various sheets in the workbook.

    4) You will probably want the welcome page to have a button on it that the user can click that will also pull up the password input box. This will enable the user to try again if he or she entered the wrong password upon the initial opening of the workbook.

    I already use a similar approach to force the enabling of macros in a couple of my projects, however, I do not require a password to open the file in those scenarios. But what I listed above is how I would approach it.

    Hopefully this is useful.

    If I helped, please click the star below the post to add to my reputation.
    Last edited by VBA Grunt; 01-08-2013 at 10:02 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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