Create a new workbook using a macro
- Click on Tools in the menu bar. From the Macro option select Visual Basic.
- In the Visual Basic Editor menu bar click on insert and then Module.
- First define a macro name like AddNew()
- We then assign it to an object variable called NewBook
- In our example, the Excel Workbook object returned by the Add method is assigned to the object variable, NewBook.
- Next, several properties of NewBook are set using the ‘With’ block. Inside the block you can easily control the new Excel workbook properties using the object variable.
- The ‘SaveAs’ part of the code will save the file in your default folder mostly MyDocuments and you can see the filename in the title bar of the workbook when you run the macro.
- Watch the video to see how the macro is implemented. Also, the code is given below for your reference.
Set NewBook = Workbooks.Add
.Title = “Employee Details”
.Subject = “Employees”