Share via


Single-Use vs. Multi-Use Applications

Whether you return a reference to a new instance of the Application object or an existing instance depends on whether the application's default behavior is as a single-use or a multi-use application. A single-use application causes a new instance of that application to be created whenever an object variable is instantiated in any host application. For example, Microsoft® Word is a single-use application, so the following code creates a new instance of Microsoft® Word regardless of how many instances of Word might be running already:

Dim wdApp aAs Word.Application
Set wdApp = New Word.Application

A multi-use application makes it possible for host applications to share the same instance of the application. The next example creates a new instance of Microsoft® Outlook® only if Outlook is not running when the code is executed. Because Outlook is a multi-use application, if Outlook is running already when this code is run, the object variable points to the currently running instance.

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application

The following table shows the default behavior for each Office application.

Application Application type
Access Single-use
Excel Single-use
FrontPage Single-use
Outlook Multi-use
PowerPoint Multi-use
Word Single-use

You can use the GetObject function to create an object variable that references a currently running instance of a single-use application.

If you create an object variable that points to a multi-use application (Outlook or Microsoft® PowerPoint®) and an instance of the application is running already, any method you use to create the object variable will return a reference to the running instance. For example, if Outlook is running already, the following lines of code all return a reference to the same instance of Outlook:

Dim olApp1 As Outlook.Application
Dim olApp2 As Outlook.Application
Dim olApp3 As Outlook.Application

Set olApp1 = New Outlook.Application
Set olApp2 = CreateObject("Outlook.Application")
Set olApp3 = GetObject(, "Outlook.Application")

See Also

Office Application Automation | Setting References | Object Variable Declaration | Creation of Object Variables to Automate Another Office Application | Automating the Visual Basic Editor | The Set Statement and the New Keyword in Automation | Using the CreateObject and GetObject Functions | Working with Documents That Contain Startup Code | Shutting Down Objects Created by Using Automation