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:
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
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.
Create New Workbook & Save
You can also create a new Workbook and immediately save it:
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:
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):
VBA Coding Made EasyStop 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!