How do I save a specific sheet to a new workbook using Excel VBA?
I have multiple sheets with names "Sheet1", "Sheet2", "Sheet3" and so on.
I'd like to save all, in individual workbooks, with a single click.
This is returns an alert
Method Save as of object workbook failed
Sub SaveSplitSheet()
Dim ws As Worksheet
Dim wb As Workbook
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "Sheet" & "*" Then
Application.DisplayAlerts = False
ws.Copy
ActiveWorkbook.SaveAs "/Users/Tukiyem/Downloads", FileFormat:=56
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
End If
Next
End Sub
Found the answer-> the code below saves multiple sheets that contain name "sheet...." as individual workbooks.
Sub SaveAsInLoop()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "Sheet" & "*" Then
Application.DisplayAlerts = False
ws.Copy
ActiveWorkbook.SaveAs "/Users/Tukiyem/Downloads/" & ws.Name & ".xlsx", FileFormat:=51
ActiveWorkbook.Close SaveChanges:=True
Application.DisplayAlerts = True
End If
Next
End Sub