Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

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
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks for the help
You're welcome!