How To Create A New Workbook In Excel Vba
Create New Workbook in Excel VBA
Description:
Sometimes we may want to open or create new workbook using VBA.You can set the newly created workbook to an object, so that it is easy to refer to your workbook to do further tasks.
Solution(s):
The following Macros will allow to open or create new workbook using Add method.
Create New Workbook in Excel VBA – Example Cases:
- Create new workbook
- Create an Object for newly created workbook
Create new workbook
You can use the following code to create new Workbook and save in the C drive using Add method.
Code:
Sub AddNewWorkbook1() 'Adding New Workbook Workbooks.Add 'Saving the Workbook ActiveWorkbook.SaveAs "C:\WorkbookName.xls" 'OR ActiveWorkbook.SaveAs Filename:="C:\WorkbookName1.xls" End Sub
Explanation:
- Workbooks.Add method will add a new workbook
- ActiveWorkbook.SaveAs method will save the active workbook to a specific location with specified File name
Output:
You should see newly opened workbook along with existing workbook.
Instructions:
- Open an excel workbook
- Press Alt+F11 to open VBA Editor
- Insert a new module from Insert menu
- Copy the above code and Paste in the code window
- Press F5 to see the output
- You should see newly opened workbook as shown above
- Save the file as macro enabled workbook
Create an object for newly created workbook
You can set the newly created workbook to an object, so that it is easy to refer to your workbook to do further tasks.
Code:
sub AddNewWorkbook2() Dim wkb as Workbook 'Adding New Workbook Set wkb = Workbooks.Add 'Saving the Workbook wkb.SaveAs "C:\WorkbookName.xls" 'OR wkb.SaveAs Filename:="C:\WorkbookName1.xls"</span></code> End Sub
Output:
You should see newly opened workbook along with existing workbook.
Instructions:
- Open an excel workbook
- Press Alt+F11 to open VBA Editor
- Insert a new module from Insert menu
- Copy the above code and Paste in the code window
- Press F5 to see the output
- You should see newly opened workbook as shown above
- Save the file as macro enabled workbook
Premium Project Management Templates
120+ Professional Project Management Templates!
A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.
LIMITED TIME OFFER
Advanced Project Planning Templates
Excel Templates
120+ Project Management Templates Pack
Excel | PowerPoint | Word
ULTIMATE RESOURCE MANAGEMENT TEMPLATE
Excel Template
50+ Essential Project Management Templates
Excel | PowerPoint | Word
Project Portfolio Management Templates
Excel | PowerPoint Templates
50+ Excel Project Management Templates
Excel Templates
Share This Story, Choose Your Platform!
Related Posts
How To Create A New Workbook In Excel Vba
Source: https://analysistabs.com/excel-vba/create-new-workbook/
Posted by: cochranhaustrand.blogspot.com
3 Comments
Thank you for sharing your info. I really appreciate your efforts and I am waiting for your next write ups thank you once again.
Can you show how to use the 'template' option when you .Add
i have multiple excel .
all the excel combined one excel and saved given path , excel name date format .
could you please given code