Option Explicit
Sub CloneFiles()
Dim myBook As Workbook
Dim ws As Worksheet
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim fNum As Long, CalcMode As Long
'Fill in the path\folder where the files are
MyPath = "C:\Users\Ron\test"
'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
'Fill the array(myFiles)with the list of Excel files in the folder
fNum = 0
Do While FilesInPath <> ""
fNum = fNum + 1
ReDim Preserve MyFiles(1 To fNum)
MyFiles(fNum) = FilesInPath
FilesInPath = Dir()
Loop
'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
'Loop through all files in the array(myFiles)
If fNum > 0 Then
For fNum = LBound(MyFiles) To UBound(MyFiles)
Set myBook = Nothing
On Error Resume Next
Set myBook = Workbooks.Open(MyPath & MyFiles(fNum))
On Error GoTo 0
If Not myBook Is Nothing Then
For Each ws In myBook.Worksheets
ws.UsedRange.Copy
ws.UsedRange.PasteSpecial xlPasteValues
Next ws
myBook.SaveAs MyPath & "Cloned_" & myBook.Name
myBook.Close
End If
Next fNum
End If
ExitTheSub:
'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub