These to macros might work
Public Sub SaveCopy2NewBook()
Dim FName As String
Dim FPath As String
Dim NewBook As Workbook
FPath = "G:\Exceptions"
FName = "Exceptions" & Format(Date, "ddmmyy") & ".xls"
Set NewBook = Workbooks.Add
ThisWorkbook.Sheets("DataSort").Copy Before:=NewBook.Sheets(1)
If Dir(FPath & "\" & FName) <> "" Then
MsgBox "File " & FPath & "\" & FName & " already exists"
Else
NewBook.SaveAs Filename:=FPath & "\" & FName
End If
End Sub
Public Sub SaveCopy2WorkBook(WB As Workbook)
Dim FName As String
Dim FPath As String
FPath = WB.Path
On Error GoTo errorFound
ThisWorkbook.Sheets("DataSort").Copy Before:=WB.Sheets(1)
GoTo exitSub
errorFound:
MsgBox "Error: " & Err.Description, vbCritical, "Error Number: " & Err.Number
exitSub:
Err.Clear
On Error GoTo 0
End Sub
The first one is the one that just creates a new workbook and does it
The second one expects and open workbook and that you pass the workbook as parameter
Your own code whatever you have
and the syntax is
Call SaveCopy2WorkBook(the workbook)
Bookmarks