Hi,
These macros should lock and unlock all excel files in a directory, password is "test"
Sub ProtectBooks()
Dim wBk As Workbook
Dim sType As String
Dim sPath As String
Dim sFile As String
sPath = "C:\Users\dave\Desktop\New folder (2)\"
sType = "*.xlsx"
sFile = Dir(sPath & sType)
Do While sFile <> ""
Set wBk = Workbooks.Open(sPath & sFile)
With wBk
Application.DisplayAlerts = False
wBk.SaveAs Filename:=.FullName, Password:="test"
Application.DisplayAlerts = True
End With
Set wBk = Nothing
Workbooks(sFile).Close False
sFile = Dir
Loop
End Sub
Sub unProtectBooks()
Dim wBk As Workbook
Dim sType As String
Dim sPath As String
Dim sFile As String
sPath = "C:\Users\dave\Desktop\New folder (2)\"
sType = "*.xlsx"
sFile = Dir(sPath & sType)
Do While sFile <> ""
Set wBk = Workbooks.Open(sPath & sFile, , , , "test")
With wBk
Application.DisplayAlerts = False
wBk.SaveAs Filename:=.FullName, Password:=""
Application.DisplayAlerts = True
End With
Set wBk = Nothing
Workbooks(sFile).Close False
sFile = Dir
Loop
End Sub
Bookmarks