How to Create a New Workbook and Name It Using Excel VBA (6 Methods)

Method 1 – Using the Add Method

We’ll use the below workbook with several Worksheets. In the first method, we will create a new workbook and name it using the Add Method in Excel VBA.

Using Add Method to Create New Workbook and Name It in Excel VBA

Open the Visual Basic Editor:

  • Go to the Developer tab and select Visual Basic.

Insert a New Module:

  • Insert a new module from the Insert menu.

Using Add Method to Create New Workbook and Name It in Excel VBA

Write the Code:

  • Copy and paste the following code into the module:
Sub Using_Add_Method_Create_New_Workbook_With_Name()
    Workbooks.Add
    ActiveWorkbook.SaveAs Filename:="F:\Using Add Method.xlsx"
End Sub

Code Breakdown

    • We created a Sub Procedure as Using_Add_Method_Create_New_Workbook_With_Name().
    • Used the Add Method and created a new workbook.
    • Saved the workbook using the SaveAs Method where I declared the Folder name and named it Using Add Method.
  • Click Save and go back to your worksheet.

Using Add Method to Create New Workbook and Name It in Excel VBA

Run the Macro:

  • Go to the Developer tab >> click on Macros.
  • Select Using_Add_Method_Create_New_Workbook_with_Name.

  • Press F5 to execute the macro.

Using Add Method to Create New Workbook and Name It in Excel VBA

  • A new workbook will be created and saved as “Using Add Method.xlsx” in the specified folder.


Method 2 – Applying the Set Object

Open the Visual Basic Editor:

  • Go to the Developer tab and select Visual Basic.

Applying Set Object to Create New Workbook and Name It in Excel VBA

Insert a New Module:

  • Insert a new module following the same steps as in Method 1.

Write the Code:

  • Copy and paste the following code into the module:
Sub Applying_Set_Object_Create_New_Workbook_With_Name()
    Dim New_Workbook As Workbook
    Set New_Workbook = Workbooks.Add
    New_Workbook.SaveAs Filename:="F:\Applying Set Object.xlsx"
End Sub

Code Breakdown

    • We created a Sub Procedure as Applying_Set_Object_Create_New_Workbook_With_Name().
    • Declared New_Workbook as Workbook.
    • Created a new workbook using the Add Method and set it as New_Workbook.
    • Saved the workbook using the SaveAs Method where I also mention the Path and named it Applying Set Object.
  • Save go back to your worksheet.

Applying Set Object to Create New Workbook and Name It in Excel VBA

Run the Macro:

  • Go to the Developer tab >> click on Macros.

  • The Macros box will appear.
  • Select Applying_Set_Object_Create_New_Workbook_with_Name.
  • Execute the macro by clicking the Run button.

Applying Set Object to Create New Workbook and Name It in Excel VBA

  • A new workbook will be created and saved as “Applying Set Object.xlsx” in the specified folder.


Method 3 – Creating and Naming a New Workbook Using a Command Button

  • Go to the Developer tab in Excel.
  • Click Insert and select Command Button from the ActiveX Controls.

Using Command Button by Creating and Naming New Workbook

  • Insert the Command Button into your worksheet and Right-click on it.

  • Choose CommandButton Object and then select Edit.

Using Command Button by Creating and Naming New Workbook

  • Rename the Command Button to Create New Workbook.

  • Now, a Command Button is added to your worksheet.

Using Command Button by Creating and Naming New Workbook

  • Right-click on the Command Button again and click View Code.

  • Write the following code:
Private Sub CommandButton1_Click()
Dim New_Workbook As Workbook
Set New_Workbook = Workbooks.Add
    New_Workbook.SaveAs Filename:="F:\Using Command Button.xlsx"
End Sub

Using Command Button by Creating and Naming New Workbook

Code Breakdown

  • We created a Private Sub Procedure called CommandButton1_Click().
  • Declared New_Workbook as a Workbook.
  • Created a new workbook using the Add Method and set it as New_Workbook.
  • Saved the workbook using the SaveAs Method, specifying the path and naming it Using Command Button.
  • Click the Save button and return to your worksheet.

  • Click Design Mode from the Developer tab.

Using Command Button by Creating and Naming New Workbook

  • Click the Command Button to create a new workbook named Using Command Button.


Method 4 – Creating a New Workbook by Copying an Existing Worksheet

  • Go to the Developer tab >> select Visual Basic.

Use of Copy Method to Create New Workbook by Copying an Existing Worksheet

  • Insert a module (following the step shown in Method 1).
  • Write the following code in your Module:
Sub Use_of_Copy_Method()
    Dim New_Workbook As Workbook
    Worksheets("Use of Copy Method").Copy
    Set New_Workbook = ActiveWorkbook
    New_Workbook.SaveAs Filename:="F:\Use of Copy Method.xlsx"
End Sub

Code Breakdown

    • We created a Sub Procedure as Use_of_Copy_Method().
    • Declared New_Workbook as Workbook.
    • Copied the worksheet using the Copy Method.
    • Set the New_Workbook as Active Workbook .
    • Saved the workbook with the path and name Use of Copy Method.
  • Save the module (following the step shown in Method 1) and return to your worksheet.
  • Go to the Developer tab >> click on Macros.

Use of Copy Method to Create New Workbook by Copying an Existing Worksheet

  • Select Use_of_Copy_Method.

  • Click Run to create a new workbook named Use of Copy Method.

Use of Copy Method to Create New Workbook by Copying an Existing Worksheet


Method 5 – Using Move Method to Create New Workbook by Moving an Existing Worksheet

  • Open Excel and go to the Developer tab.
  • Select Visual Basic to open the VBA editor.

Using Move Method to Create New Workbook by Moving an Existing Worksheet and Name it in Excel VBA

  • Insert a module (following the step shown in Method 1).
  • Write the following code in your Module.
Sub Using_Move_Method()
    Dim New_Workbook As Workbook
    Worksheets("Using Move Method").Move
    Set New_Workbook = ActiveWorkbook
    New_Workbook.SaveAs Filename:="F:\Using Move Method.xlsx"
End Sub

Code Breakdown

  • We created a Sub Procedure as Using_Move_Method().
  • Declared New_Workbook as Workbook.
  • Used the Move Method to move this worksheet.
  • Set the New_Workbook as Active Workbook .
  • Saved the workbook with the Path and name Using Move Method.
  • Save the module (following the step from Method 1) and return to your worksheet.
  • Go to the Developer tab and click on Macros.

Using Move Method to Create New Workbook by Moving an Existing Worksheet and Name it in Excel VBA

  • Select Using_Move_Method.
  • Click Run.

  • A new workbook named Using Move Method will be created.

Using Move Method to Create New Workbook by Moving an Existing Worksheet and Name it in Excel VBA


Method 6 – Creating a New Workbook Using the Range Object

  • Go to the Developer tab and select Visual Basic.

Applying Range Object to Create a New Workbook and Name it According to Cell Value in Excel VBA

  • Insert a module (following the step from Method 1).
  • Write the following code in your Module:
Sub Applying_Range_Object()
Dim New_Workbook As String
New_Workbook = ActiveWorkbook.Sheets(6).Range("B2").Value
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=New_Workbook & ".xls"
End Sub

Code Breakdown

  • We created a Sub Procedure calles Applying_Range_Object().
  • Declared New_Workbook as a String.
  • Set New_Workbook value as the content of Cell B2 from the Active Workbook.
  • Added a new workbook using the Add Method.
  • Saved the workbook with the name based on the value in Cell B2
  • Save the module (following the step from Method 1) and return to your worksheet.
  • Go to the Developer tab, click on Macros.

Applying Range Object to Create a New Workbook and Name it According to Cell Value in Excel VBA

  • Select Applying_Range_Object.
  • Click Run.

Applying Range Object to Create a New Workbook and Name it According to Cell Value in Excel VBA

  • A new workbook named according to the text in Cell B2 from the active sheet will be created.

Applying Range Object to Create a New Workbook and Name it According to Cell Value in Excel VBA

Read More: Excel VBA Calculate Workbook


Practice Section

Use this dataset to practice and learn how to use these methods.

Practice Section


Download Practice Workbook

You can download the practice workbook from here:


 

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Arin Islam
Arin Islam

Anowara Islam Arin, a graduate of Civil Engineering from Khulna University of Engineering & Technology, Bangladesh, serves as a technical content creator in the ExcelDemy project. Possessing a passion for innovation and critical thinking, she actively embraces challenges. Beyond her engineering background, Arin exhibits a keen interest in Excel, having authored numerous articles on Excel & VBA-related issues to simplify the experience for users facing obstacles in Excel. Besides, she is also interested in Advanced Excel,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo