Sub PasswordProtectMultipleWorkbooks()
Dim folderPath As String
Dim password As String
Dim fileName As String
Dim wb As Workbook
' Set the folder path and password
folderPath = "C:\path\to\your\directory\"
password = "yourpassword"
' Check if the folder path ends with a backslash, if not add it
If Right(folderPath, 1) <> "\" Then
folderPath = folderPath & "\"
End If
fileName = Dir(folderPath & "*.xls*")
Do While fileName <> ""
Set wb = Workbooks.Open(folderPath & fileName)
wb.Password = password
wb.Save
wb.Close SaveChanges:=True
fileName = Dir
Loop
End Sub
Thank you. This work. You have no idea how much time this will save me.You can start with this. Test on copy.
VBA Code:Sub PasswordProtectMultipleWorkbooks() Dim folderPath As String Dim password As String Dim fileName As String Dim wb As Workbook ' Set the folder path and password folderPath = "C:\path\to\your\directory\" password = "yourpassword" ' Check if the folder path ends with a backslash, if not add it If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\" End If fileName = Dir(folderPath & "*.xls*") Do While fileName <> "" Set wb = Workbooks.Open(folderPath & fileName) wb.Password = password wb.Save wb.Close SaveChanges:=True fileName = Dir Loop End Sub
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.Thank you. This work. You have no idea how much time this will save me.