+ Reply to Thread
Results 1 to 12 of 12

VB Code Password Protect Multiple excel files

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

    VB Code Password Protect Multiple excel files

    Hello:

    I have lots of excel file in folder "C:\Temp\"
    All files have extension with .xls or .xlsm
    All these files are password protected by say "ABCD"

    I need a VB Code to do follwowing:
    I want to change all password to "1234"

    Let me know if you have any questions.
    Thanks.

    Riz
    Last edited by rizmomin; 05-19-2015 at 04:45 PM.

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

    Re: VB Code Password Protect Multiple excel files

    Hello:

    Small change.
    Code can first Unprotect all excel files with password "ABCD"
    and then ask if user wants to protect all files with the new password.

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

    Riz

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

    Re: VB Code Password Protect Multiple excel files

    Hello Guys:

    I have worked on this and come up with some coding but need help to complete.
    Please refer to attached file with the associated VB code.

    Let me know if you have any questions.
    Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VB Code Password Protect Multiple excel files

    Hi Riz,
    try:
    Please Login or Register  to view this content.
    See how this works for you.

    //berlan

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

    Re: VB Code Password Protect Multiple excel files

    Hi Berlan:

    Super Smart...seems to work.
    Need some modification.
    1st : each file in the folder opens and then close....i want to see if i can avoid opening and closing the file.
    2nd : Pick up the new PW for each file from corresponding cell in column C.
    Example the file name listed in cell B10 , new password would be in cell C10.

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

    Riz

  6. #6
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VB Code Password Protect Multiple excel files

    I haven't figured out a way to modify the password without opening the file. You can however turn off calculations, screenupdating, etc., during the procedure to improve speed somewhat if the workbook e.g. contains volatile formulas.

    As for (2), to pick up the password, replace sPW and/or sNewPW:
    c(, 2).Value, or c.offset(,1).value, for the corresponding value in column C
    c(, 3).Value for the corresponding value in column D
    note that the reference in column B, c = c(1,1)

    Please Login or Register  to view this content.
    Let me know how that works for you.
    Last edited by berlan; 05-22-2015 at 03:56 PM.

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

    Re: VB Code Password Protect Multiple excel files

    Hello berlan:

    Ok Thanks now can u add the code to turn off manual, screen updating etc and let me try.
    Riz

  8. #8
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VB Code Password Protect Multiple excel files

    Sure, adding it here:
    Please Login or Register  to view this content.

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

    Re: VB Code Password Protect Multiple excel files

    Hi Berlan:

    Seems to work now...and it is not even opening the file.
    I thank you so mich for such a great help.
    Will test more and let you know if any problem.
    Love it.
    Riz

  10. #10
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VB Code Password Protect Multiple excel files

    Glad to help and thanks for the positive rep.

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

    Re: VB Code Password Protect Multiple excel files

    Hi Berlan:

    Would it be possible to add extra code so that it can password protect VB Code module itself also.
    If VB Coding in the file is not protected then assign same PW as workbook PW.
    If VB Coding in the file is protected then change the PW from original PW to new PW and original PW will be the same as PW for the workbook.

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

    Riz

  12. #12
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VB Code Password Protect Multiple excel files

    Hi rizmomin,

    Tricky! There's no easy way to set the VBAProject password by code that I know of. You will need to open the project window for each workbook that you go through, and to do this by code, you need to involve API functions (instead of using SendKeys). I will look into it later in the week.

    Meanwhile, perhaps start a separate thread on creating and modifying a VBAProject password, as others may be able to try it out.

    //berlan

+ 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. Replies: 4
    Last Post: 09-01-2017, 06:36 AM
  2. Password-protect excel files in folder
    By ilsley_excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2014, 06:40 AM
  3. VBA code to password protect all excels files in a folder
    By jaincool123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2014, 07:19 AM
  4. How to Password Protect Word and Excel Files
    By memopadhd7 in forum Tips and Tutorials
    Replies: 0
    Last Post: 02-24-2014, 03:01 AM
  5. Password protect Excel and Word FOLDERS (not just files)
    By Hedges Chandler in forum Excel General
    Replies: 1
    Last Post: 11-15-2005, 03:25 PM

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