Yes, it is in the "Test_File_Exists_With_Dir_v1" macro, as shown below"
Sub Test_File_Exist_With_Dir_v1()
Dim FilePath As String
Dim TestStr As String
Dim sh As Worksheet
Dim DestWb As Workbook
Dim ws1 As Worksheet
For Each sh In Worksheets
If sh.Name <> "Venue Table" Then
'path and file to check
FilePath = ThisWorkbook.Path & "\" & sh.Name & " " & "2016" & ".*"
'reset testStr
TestStr = ""
'set teststr
On Error Resume Next
TestStr = Dir(FilePath)
On Error GoTo 0
If TestStr = "" Then
If sh.Visible = -1 Then
sh.Copy
'Set Destwb to the new workbook
Set DestWb = ActiveWorkbook
'Save the new workbook and close it
With DestWb
.SaveAs ThisWorkbook.Path & "\" & sh.Name & " " & "2016", FileFormat:=51
.Close False
End With
End If
Else
If Right(TestStr, 4) = "xlsx" Then
Set DestWb = Workbooks.Open(ThisWorkbook.Path & "\" & TestStr) 'change xlsx if this is not your default excel extention
Set ws1 = ActiveSheet
sh.Range("A2:N" & sh.Cells(Rows.Count, "A").End(xlUp).Row).Copy
ws1.Range("A" & ws1.Cells(Rows.Count, "A").End(xlUp).Row + 1).PasteSpecial xlPasteValuesAndNumberFormats
ws1.Range("A2").CurrentRegion.Sort Key1:=ws1.Range("A2"), Order1:=xlAscending, Key2:=ws1.Range("C2"), Order2:=xlAscending, Header:=xlGuess
DestWb.Close True
Else
MsgBox TestStr & " exist but is not an Excel file"
End If
End If
End If
Next
End Sub
Bookmarks