Application object

The Application object allows you to work with the Excel application.

Creating the application

Use new keyword to create a new instance of Excel.

{Create a new instance of Excel.}
app = new Excel.Application();

Use the COM_CreateObject() function to create a new instance of Excel when using Distributed COM (DCOM). In the following example, a new instance of Excel is created on the computer “SystemServer”.

{Create a new instance of Excel.}
app = COM_CreateObject("Excel.Application", "SystemServer");

Retrieving an existing application

Use the COM_GetObject() function to retrieve a running instance of Excel.

{Retrieve a running instance of Excel.}
app = COM_GetObject("Excel.Application");

Showing and hiding an application

The Visible property from the Application object allows you to show or hide Excel. Setting the Visible property to true shows the application.

{Show the application.}
app.Visible = true;

Setting the Visible property to false hides the application.

{Hide the application.}
app.Visible = false;

The new keyword and the COM_CreateObject() function return hidden instances of an application. Use the Visible property to show a hidden instance of an application.


Hiding and showing warning messages

When you integrate with Excel, dialog boxes containing warnings can stop the application. To hide warning messages, set the DisplayAlerts property to false.

{Hide warning messages.}
app.DisplayAlerts = false;

To show warning messages, set the DisplayAlerts property to true.

{Show warning messages.}
app.DisplayAlerts = true;

Hiding warnings prevents the user from seeing the messages displayed by an application. Your code must still handle the errors or other exceptional conditions that caused Excel to display warning messages.


Closing an application

After you have finished using the application, you can close it with the Quit method.

{Close the application.}
app.Quit();

If Excel is closed with an unsaved workbook or worksheet, a warning message appears. To prevent a dialog from appearing, do one of the following:

 


Documentation Feedback