create new workbook from excel tab and save to new location and close it and then grab the next tab and save to a different location using VBA

34 views Asked by At

I am not from software background and trying to write a macro to avoid repeated work

I would like the code to grab a tab from an excel workbook create a new workbook and save it with a new name and save it to a new file and then to continue grabbing the next tab and do the same as the first step but save it to a new location. the first code below works but I need to manually change the tab each time and location can I automate this with one code with using same code but say next?

Option Explicit

Sub Copysheetandsave()
    Dim sourceWs As Worksheet, savePath As String

    Set sourceWs = ThisWorkbook.Worksheets("203")

    savePath = "C:\Users\"
    sourceWs.Copy
    With ActiveWorkbook
        .SaveAs Filename:=savePath & " 2023 YTD.xlsx"
         .Close False
    End With

End Sub
0

There are 0 answers