Results 1 to 2 of 2

Password-protect excel files in folder

Threaded View

ilsley_excel Password-protect excel files... 12-10-2014, 12:34 PM
ilsley_excel Re: Password-protect excel... 12-11-2014, 06:40 AM
  1. #1
    Registered User
    Join Date
    12-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    39

    Talking Password-protect excel files in folder

    Hi,

    I'm hoping someone can help. I'm trying to build a quick tool that displays a list of all Excel files from a given folder and then password-protect each one.

    So far, I've managed to do this:

    1) Look for all Excel files in a given folder and display their names in Column B (i.e. from Cell B9 down).
    2) Generate a password in Column C (i.e. from Cell C9 down) automatically based on the filename - I've built this in to the macro I built in step 1.


    And now I've hit a snag. I now want to loop through each file from the list in Column B (from B9 down) and assign the corresponding password to it from Column C (from C9 down). I wrote the following code for it, but it doesn't seem to work:

    ==============================================

    Sub ProtectExcelFiles()
    
        Dim Wbk As Workbook
        Dim Ws1 As Worksheet
        Dim FilenameCell As Range
        Dim PasswordCell As Range
        Dim Lastrow As Integer
        Dim xlFile As String
        Dim usrPassword As String
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
    
        Set Ws1 = Sheets("PasswordProtector")
        Lastrow = Ws1.Cells(Rows.Count, 1).End(xlUp).Row
    
        For Each FilenameCell In Ws1.Range("B9:B" & Lastrow)
    
            xlFile = FilenameCell.Value
            PasswordCell = Cells(FilenameCell.Column + 1, FilenameCell.Row)
            
            usrPassword = PasswordCell.Value
                    
            Set Wbk = Workbooks.Open(xlFile)
            Wbk.ReadOnlyRecommended = False
            Application.DisplayAlerts = False
            Wbk.SaveAs xlFile, WriteResPassword:=usrPassword
            Application.DisplayAlerts = True
            Wbk.Close False
    
        Next
            
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    
    End Sub
    ==============================================


    Any ideas??


    Thanks in advance!
    Last edited by FDibbins; 12-10-2014 at 01:00 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. 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
  2. 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
  3. [SOLVED] How to password protect a complete folder in excel
    By daisys_dad in forum Excel General
    Replies: 0
    Last Post: 08-10-2006, 09:35 AM
  4. [SOLVED] 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
  5. [SOLVED] Can you password protect a folder.
    By Shrimp913 in forum Excel General
    Replies: 1
    Last Post: 03-04-2005, 04:06 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