+ Reply to Thread
Results 1 to 11 of 11

VB Code to password protect the excel file

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to password protect the excel file

    Hello:

    I have lots of excel file.
    All these files need to be protected with the password with a macro to avoid doing it manually as there are lots of file.

    I will have Password in Sheet1 of cell A1 of each file.

    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to password protect the excel file

    Hello Riz,

    If you are protecting individual workbooks, where do you have the paths?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to password protect the excel file

    Hi Leith:

    All files will be either .xls or .xlsm
    Each file will have say "Sheet1" and each will have PW in cell A1.
    Let's say i have 100 Files in C:\Temp\ folder.
    Currently all files are unprotected.
    Now rather then opening up each file manually and adding PW will take long time.
    So i need a VB Macro to go thru each Closed file and get the Pw from Sheet1, Cell A1 and save that file with the PW.
    I hope this clears my requirement.
    Please let me know if you have any questions.
    Thanks.

    Riz

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to password protect the excel file

    Hello Riz,

    You will need to change Path to the folder where the files are. This open all xls, xlsx, and xlsm files and set the passwords using cell "A1" on "Sheet1".

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-06-2015 at 08:06 PM. Reason: Corrected Typo

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to password protect the excel file

    Hi Leith :

    I am getting error at " Files.Filter 64, "*.xls;*.xlsx;*.xlsm" "

    I have 2 files in C:\Temp1 namely Book1.xlsx and Book2.xlsx

    i have changed the path to C:\Temp1

    Please refer to atatched files.
    Riz
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to password protect the excel file

    Hello Riz,

    My fauilt. It is typographical error.

    Change Files.Filter 64, "*.xls;*.xlsx;*.xlsm" to oFiles.Filter 64, "*.xls;*.xlsx;*.xlsm".

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to password protect the excel file

    Hi Leith:

    Its working great except small issue.
    It is asking to enter the PW twice, need to enter just once if possible.
    Thanks
    Riz

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to password protect the excel file

    Hello Riz,

    You shouldn't be prompted for the password. When are you receiving the prompts: Workbook Open, Workbook Close, or both?

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to password protect the excel file

    Hi Leith:

    Yes you are correct.
    When I try to open it ask the PW twice instead of 1 time.
    Thanks
    Riz

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Code to password protect the excel file

    Hello Riz,

    The macro just assigns the password to the workbook. Once the workbook has a password you will prompted to enter the password when the workbook is opened.

    Are you entering it a second time as a confirmation to the first entry?

  11. #11
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to password protect the excel file

    Hi Leith:
    I am sorry to get back late.
    Yes, I entering it a second time as a confirmation to the first entry.
    This will work....Thanks a lot
    Riz

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VB Code Password Protect Multiple excel files
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-25-2015, 07:14 PM
  2. Password Protect Excel File
    By akynyemi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2013, 09:03 AM
  3. password protect excel file deletion
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2013, 06:46 PM
  4. [SOLVED] Password protect an excel file?
    By in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2009, 10:53 AM
  5. [SOLVED] How do I use a password to protect an Excel file from peeping eyes?
    By Fat Cat in forum Excel General
    Replies: 1
    Last Post: 01-30-2005, 10:06 AM
  6. [SOLVED] How do I use a password to protect an Excel file from peeping eyes?
    By Fat Cat in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-30-2005, 10:06 AM
  7. [SOLVED] How do I use a password to protect an Excel file from peeping eyes?
    By Fat Cat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2005, 10:06 AM

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