Is there anyway to only open files that has a password, then change to new password, save file, then close? The script I'm using now opens ALL files, (with or without password) then saves it with new password. The other problem is some files has password "test123" while some has password "123test". How can I open all files by trying out both passwords? Lastly, I would like to open other document types (word, pdf) as well. Thank you.
Sub ProtectAll()
Dim wBk As Workbook
Dim sFileSpec As String
Dim sPathSpec As String
Dim sFoundFile As String
sPathSpec = "c:\mypath"
sFileSpec = "*.xl*"
sFoundFile = Dir(sPathSpec & sFileSpec)
Do While sFoundFile <> ""
Set wBk = Workbooks.Open(sPathSpec & sFoundFile, Password:="test123")
With wBk
Application.DisplayAlerts = False
wBk.SaveAs Filename:=.FullName, _
Password:="pass"
Application.DisplayAlerts = True
End With
Set wBk = Nothing
Workbooks(sFoundFile).Close False
sFoundFile = Dir
Loop
End Sub
Sub ProtectAll()
Dim wBk As Workbook
Dim sFileSpec As String
Dim sPathSpec As String
Dim sFoundFile As String
sPathSpec = "c:\mypath"
sFileSpec = "*.xl*"
sFoundFile = Dir(sPathSpec & sFileSpec)
Do While sFoundFile <> ""
Set wBk = Workbooks.Open(sPathSpec & sFoundFile, Password:="test123")
With wBk
Application.DisplayAlerts = False
wBk.SaveAs Filename:=.FullName, _
Password:="pass"
Application.DisplayAlerts = True
End With
Set wBk = Nothing
Workbooks(sFoundFile).Close False
sFoundFile = Dir
Loop
End Sub