Adding and Saving Workbooks

October 27th, 2008 | Categories: VBA | Tags:

The following code will prompt the user for the name of a workbook. It will then create and save a new
workbook with the same name.

Private Sub CommandButton1_Click()
Dim Workbook_Name As String
Dim New_Workbook As Workbook
Set New_Workbook = Nothing
Workbook_Name = InputBox(Prompt:="Workbook Name.", Title:="Enter the WorkBook Name :")
Set New_Workbook = Workbooks.Add
With New_Workbook
.Activate
.SaveAs Workbook_Name
End With

End Sub

To download the .XLSM file for this article, click here

  1. October 27th, 2008 at 19:25
    Reply | Quote | #1

    GetSaveAsFileName is a much more powerful way to get a file name from a user. It allows browsing to a desired directory with the familiar “Save” dialog.