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

Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
  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.

    • pamela russell
      September 14th, 2010 at 17:53
      Reply | Quote | #2

      Please send me GetSaveAsFileName code, assuming it is a freebie.

      Thanks!

      Pam