To create a new workbook in Visual Basic, you use the Add method. The following procedure creates a new workbook. Microsoft Excel automatically names the workbook BookN, where N is the next available number. The new workbook becomes the active workbook.
Sub AddOne()
Workbooks.Add
End Sub
A better way to create a new workbook is to assign it to an object variable. In the following example, the Workbook object returned by the Add method is assigned to an object variable, newBook
. Next, several properties of newBook
are set. You can easily control the new workbook using the object variable.
Sub AddNew()
Set newBook = Workbooks.Add
With newBook
.Title = "1995 Sales"
.Subject = "Sales"
.SaveAs filename:="95Sales.xls"
End With
End Sub