Question : Password Protect Multiple Excel Files

How can I password protect all the excel files in a given directory with the same password so that you have to enter the password to open the files?

Answer : Password Protect Multiple Excel Files

Here is a macro that will do that for you.  I also uploaded a workbook that is already working.  Just download it and run the macro...select any file in any folder and it will password every file in that folder.  You have to go into the code and on line 19 change this:
Password:="password"

to the password you want (just the part betweeen the quotes)

It only works on .xls files...it does not work on 2007 files.  If you need it to work on 2007 files, then let me know...
I didn't test it so try it out on a small folder first...(but I'm pretty sure it will work)

:-)
Albert
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Sub GetValues()
Dim strPath As String
Dim OtherWb As Workbook
Dim EachFile As String
 
Application.ScreenUpdating = False
 
    strPath = Application.GetOpenFilename(fileFilter:="Pick any xls file (*.xls, *.xls")
    If strPath = "" Then Exit Sub
    strPath = Left(strPath, InStrRev(strPath, "\") - 1)
    
    EachFile = Dir(strPath & "\*.xls")
    Do While EachFile <> ""   ' Start the loop.
                MsgBox strPath & "\" & EachFile
        If EachFile = ThisWorkbook.Name Then GoTo nxt
        Set OtherWb = Workbooks.Open(EachFile, False)
        
            Application.DisplayAlerts = False
                OtherWb.SaveAs strPath & "\" & EachFile, Password:="password"
            Application.DisplayAlerts = True
        
        OtherWb.Close False
nxt:
       EachFile = Dir    ' Get next xls file
    Loop
 
    Application.ScreenUpdating = True
    Set OtherWb = Nothing
End Sub
 
 
Random Solutions  
 
programming4us programming4us