Murray Brown
asked on
Excel VBA Save two sheets into new workbook
Hi
I am using the following code to save a worksheet as a separate file. I now want to include a second sheet "SheetX" in that new file as well. How do I create a new file with these two sheets?
For Each xWs In ActiveWorkbook.Worksheets
oSheetName = xWs.Name
'First check if the sheet is the copy of the tax invoice and make separate file
If oSheetName = "Copy Tax Invoice" Then
xWs.Copy
Dim oFileAndPath As String
oFileAndPath = xPath & "\Ejected Files\" & oDate & " " & oShaft & ".xlsx"
ActiveWorkbook.SaveAs Filename:=oFileAndPath, FileFormat:=56
ActiveWorkbook.Close False
End If
'Next delete the sheet if it is not numeric
'If IsNumeric(oSheetName) = False Then
'Set wsDelete = Sheets(oSheetName)
'wsDelete.Delete
'End If
Next
I am using the following code to save a worksheet as a separate file. I now want to include a second sheet "SheetX" in that new file as well. How do I create a new file with these two sheets?
For Each xWs In ActiveWorkbook.Worksheets
oSheetName = xWs.Name
'First check if the sheet is the copy of the tax invoice and make separate file
If oSheetName = "Copy Tax Invoice" Then
xWs.Copy
Dim oFileAndPath As String
oFileAndPath = xPath & "\Ejected Files\" & oDate & " " & oShaft & ".xlsx"
ActiveWorkbook.SaveAs Filename:=oFileAndPath, FileFormat:=56
ActiveWorkbook.Close False
End If
'Next delete the sheet if it is not numeric
'If IsNumeric(oSheetName) = False Then
'Set wsDelete = Sheets(oSheetName)
'wsDelete.Delete
'End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome!
ASKER