The Application Object

If your VBA code is running within Excel, then the Excel application object is automatically available to you by using the Application keyword. Thus, you could write

Workbooks.Add

The implicit reference causes the “Workbooks” keyword to automatically apply to the Excel.Application object.

If you are automating Excel from another Office application, you must explicitly create an instance of Excel and use a reference to that instance to access the Application object. For example, the following code could be run from any other Office application to start a hidden copy of Excel, create a new workbook, and put the value 12 in cell A1 of Sheet1:

 Dim MyXLApp As Excel.Application Set MyXLApp = New Excel.Application MyXLApp.Workbooks.Add ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.