user7444699
user7444699

Reputation:

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

Upvotes: 3

Views: 30680

Answers (1)

user4039065
user4039065

Reputation:

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

Upvotes: 8

Related Questions