Create an Instance of the Other Application
 
 
 

Once you have referenced an application's object library you must create an instance of the application. This is just a fancy way of saying you need to start the other application programmatically so your code will have valid objects to work with.

To do this, first declare a variable that will represent the other application. You do this the same way as built-in objects, by using a Dim statement. You should qualify the type of application in your Dim statement. For example, this Dim statement declares an object variable of type Excel.Application:

Dim ExcelAppObj as Excel.Application

After you declare the variable, use the Set statement with the New keyword to set the variable equal to a running instance of the application. For example, the following Set statement sets the variable declared above equal to the Excel application. The New keyword starts a new session of Excel.

Set ExcelAppObj = New Excel.Application
NoteSome applications allow only one running instance of the application at a time. Using the New keyword on such an application will establish a reference to the existing instance and will not launch a new session of the application.