VBA Create New Workbook (Excel File)

HomeVBA TutorialVBA Create New Workbook (Excel File)

To create a new workbook using VBA, you need to use the “Workbooks.Add” method. When you use this method, it inserts a new workbook (without saving it) and activates it after that. It works like when you press the keyboard shortcut CONTROL + N. You can also use a template to insert a new workbook.

Create a New Workbook using VBA

Make sure to add the developer tab to the ribbon to enter this code into the VBE.

  1. Type the keyword “Workbooks” to refer to the workbook object.
  2. After that, type a dot.
  3. Here’s you’ll have a list of properties and methods to select.
  4. Select “Add” from that list or type it.
Sub vba_new_workbook()
End Sub

Add a New Workbook using a Template

As I said, we are using the Workbooks.Add method. With this method, there’s an argument (optional) that you can use to refer to a file as a template.

Workbook.Add Template (Optional)

Let’s say you have workbook and want to have the new workbook exactly same like it, you can refer to it as a template.

Workbooks.Add Template:="C:\Users\Dell\Desktop\book1.xlsx"

When you run the above code, it takes the reference from the “book1” which is saved on the desktop. The template workbook has 6 worksheets and the new workbook has exactly the same number of worksheets.

Apart from this, you can use the default arguments to decide what type of sheet you want to have in the new workbook.

  1. xlWBATChart: Chart Sheet
  2. xlWBATExcel4IntlMacroSheet: Macro Sheet Version 4
  3. xlWBATExcel4MacroSheet: Macro Sheet (International) Version 4
  4. xlWBATWorksheet: Worksheet

Create a New Excel Workbook and Save it

When you create a new workbook, Excel open it but will not save it with the Add method. So for this, you need to use the SaveAs method.

Sub vba_create_workbook()
ActiveWorkbook.SaveAs "C:\users\dell\desktop\myBook.xlsx"
End Sub
  1. First, use the workbook.add to create a new workbook.
  2. Next, refer to the active workbook and use the SaveAs method.
  3. In the SaveAs method, use the path where you want to save the workbook along with the name of the file.
  4. In the end, run the code.

More on VBA Workbooks

VBA Save Workbook | VBA Close Workbook | VBA Delete Workbook | VBA ThisWorkbook | VBA Rename Workbook | VBA Activate Workbook | VBA Combine Workbook | VBA Protect Workbook (Unprotect) | VBA Check IF a Workbook is Open | VBA Open Workbook | VBA Check IF an Excel Workbook Exists in a Folder