Macro to save only the active worksheet

user7444699 picture user7444699 · Feb 23, 2018 · Viewed 18.3k times · Source

In the below code it saves the complete workbook. I want to save only the active worksheet.

Sub sbVBS_To_SAVE_ActiveWorkbook()
ActiveWorkbook.Save
End Sub

Answer

user4039065 picture user4039065 · Feb 23, 2018

Copying a worksheet to no location automatically creates a new workbook in the foreground with a copy of the worksheet as the only worksheet in the new workbook.

Sub test()
    worksheets("sheet3").copy
    'there is now a new active workbook
    with activeworkbook
        'save it
        .SaveAs Filename:="some file path and filename without extension", FileFormat:=xlOpenXMLWorkbook
        'optionally close it
        .close savechanges:=false
    end with
End Sub