The following VBA procedure demonstrates how to create and open a new workbook in Excel. For verification, it displays the number of currently open workbooks both before and after the new workbook is created:
Sub NeueMappe() MsgBox "Before: " & Workbooks.Count & " workbook(s)" Workbooks.Add MsgBox "After: " & Workbooks.Count & " workbook(s)" End Sub
Explanation:
This procedure makes use of the Add() method of the Workbooks object. When Workbooks.Add is called, Excel creates a new, blank workbook and immediately opens it. This new workbook also becomes the active workbook, meaning it is now the one in focus and ready for user interaction.
At the same time, the new workbook is added to the Workbooks collection. You can observe this by comparing the output of Workbooks.Count before and after the Add() method is executed: the count increases by one, confirming that a new workbook has been successfully created and included in the collection of currently open workbooks.