A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Download this file:
https://www.dropbox.com/s/700hbz18bsc7nu2/FileSearch.cls?dl=1
Make a new Excel file
Open the VBA editor
Import the downloaded file
Create a new regular module
Paste in the code below
Customize the constants at the top of the sub
Run it
After the macro is finished all files that causes an error are listed in the sheet.
Andreas.
Sub Test()
'Setup the passwords here:
Const OldPassword = "old"
Const NewPassword = "new"
'Path to the folder that contains the files
Const FilePath = "C:\Users\Test"
'No need to change anything below this line
Dim FS As New FileSearch
Dim Wb As Workbook
Dim FName
Dim Dest As Range
With FS
'Setup the search arguments
.LookIn = FilePath
.FileName = "*.xls*"
.SearchSubFolders = True
'Go
.Execute
'Prepare
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'First cell for errors
Set Dest = Range("A1:B1")
Dest = Array("Error", "Filename")
Set Dest = Dest.Offset(1)
On Error GoTo Errorhandler
For Each FName In .FoundFiles
'Skip ourself
If StrComp(Mid(FName, InStrRev(FName, "") + 1), ThisWorkbook.Name) = 0 Then GoTo Skip
'Open with the old password
Set Wb = Workbooks.Open(FName, False, Password:=OldPassword)
'Save with a new password
Wb.SaveAs FName, Wb.FileFormat, NewPassword
'Close the file
Wb.Close
Skip:
Next
'Clean up
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End With
Exit Sub
Errorhandler:
Dest = Array(Err.Number, FName)
Set Dest = Dest.Offset(1)
Resume Skip
End Sub