Create Workbook with Name in Excel VBA. Where Workbook represents an object. It is part of workbooks collection. We know that Add is a method to create new workbook in Excel VBA. Default name of workbook is Book1, Book2, … BookN. Where N represents the next available number. Like this we can crate any number of workbooks in Excel.
The new Excel workbook default extension is “.xlsx”. We can also save as xlsm,xls,xla,xlts,xlsb,xml etc. We usually create countless number of times new workbook. Press Ctrl+N keyboard shortcut key to create new workbook from the opened workbook.
Syntax to Create New Workbook
Here is the following syntax to create new Workbook.
Workbooks.Add
Macro to Create Workbook with Name in Excel VBA
Here is the following example Macro to Create New Workbook with Name in Excel VBA. In the below procedure add is a method to create new workbook. You can change file name as per your requirement.
'Create New Workbook with Name in Excel VBA Sub VBA_Create_New_Workbook_With_Name() 'Create New Workbook Workbooks.Add 'Save Above Created New Workbook ActiveWorkbook.SaveAs Filename:="D:\VBAF1\Test.xlsx" End Sub
VBA Code to Create New Workbook with Name using object
Let us see the following example Macro to Create New Workbook with Name and assigned to an object in Excel VBA. In the following procedure set is used to define workbook object.
'Create Workbook with Name in Excel VBA Sub VBA_Create_New_Workbook_With_Name_Ex2() 'Variable declaration Dim sWorkbook As Workbook 'Create New Workbook Set sWorkbook = Workbooks.Add 'Save Above Created New Workbook sWorkbook.SaveAs Filename:="D:\VBAF1\Test.xlsx" End Sub
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays in Excel Blog
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers