Application object

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

Creating the application

Use the new keyword to create a new instance of Word.

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

When using Distributed COM (DCOM), create a new instance of Word with the COM_CreateObject() function. In the following example, a new instance of Word is created on the computer “SystemServer”.

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

Retrieving an existing application

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

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

Showing and hiding an application

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

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

Setting the Visible property to false hides an application.

{Hide an 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 Word, dialog boxes containing warnings can stop the application. To hide or show warning messages, set the DisplayAlerts property to the appropriate constant contained in the wdAlertLevel enumeration. To hide all messages, set the property to wdAlertsNone.

{Hide messages.}
app.DisplayAlerts = Word.wdAlertsNone;

To show all messages, set the DisplayAlerts property to wdAlertsAll.

{Show warning messages.}
app.DisplayAlerts = Word.wdAlertsAll;

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 Word to display warning messages.


Closing an application

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

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

You can use constants contained in the wdSaveOptions enumeration to specify whether currently open documents are saved when Word is closed. The following table lists the available values and the behavior they specify.

[spacer]

Constant

Behavior

wdDoNotSaveChanges

Doesn’t save the changes in the open documents

wdSaveChanges

Saves changes without prompting the user

wdPromptToSaveChanges

Asks the user if they would like to save changes


{Save the open documents without prompting the user. Then close the application.}
app.Quit(Word.wdSaveChanges);


Documentation Feedback