Quantcast
Channel: Active questions tagged tabs - Stack Overflow
Viewing all articles
Browse latest Browse all 587

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 [duplicate]

$
0
0

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 ExplicitSub 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 WithEnd Sub

Viewing all articles
Browse latest Browse all 587

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>