VBA – Create New Workbook (Workbooks.Add)
Written by
Reviewed by
In this Article
This tutorial will demonstrate different methods to create a new workbook using VBA.
Create New Workbook
To create a new workbook simply use Workbooks.Add:
Workbooks.Add
The newly added Workbook is now the ActiveWorkbook.
You can see this using this code:
Sub AddWB()
Workbooks.Add
MsgBox ActiveWorkbook.Name
End Sub
Create New Workbook & Assign to Object
You can use the ActiveWorkbook object to refer to the new Workbook. Using this, you can assign the new Workbook to an Object Variable:
Dim wb as Workbook
Workbooks.Add
Set wb = ActiveWorkbook
But, it’s better / easier to assign the Workbook immediately to a variable when the Workbook is created:
Dim wb As Workbook
Set wb = Workbooks.Add
Now you can reference the new Workbook by it’s variable name.
MsgBox wb.Name
Create New Workbook & Save
You can also create a new Workbook and immediately save it:
Workbooks.Add.SaveAs Filename:="NewWB"
This will save the Workbook as an .xlsx file to your default folder (ex. My Documents). Instead, you can customize the SaveAs with our guide to saving Workbooks.
Now you can refer to the Workbook by it’s name:
Workbooks("NewWB.xlsx").Activate
This code will Activate “NewWB.xlsx”.
Create New Workbook & Add Sheets
After creating a Workbook you can edit it. Here is just one example to add two sheets to the new Workbook (assuming it’s the ActiveWorkbook):
ActiveWorkbook.Worksheets.Add Count:=2
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!Learn More!