Finance

Charts

Statistics

Macros

Search

Creating a New Workbook in Excel VBA

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.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx