Search code examples
vbaexcelsave-as

Macro to save only the active worksheet


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

Solution

  • 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