Previous Topic

Next Topic

Book Contents

Book Index

Home Page

Integrating COM Applications

VBScript provides powerful features for integrating with other applications. In particular, support for Microsoft's Component Object Model (COM) compliant applications is provided through the "CreateObject" and "GetObject" functions.

COM is a standard that defines how applications can communicate with each other. An application that provides a COM interface allows other applications to communicate with it. The VBScript "CreateObject" and "GetObject" functions provide direct access to applications that support COM interfaces.

COM is the modern successor of OLE Automation. The term "Automation" will often be used in other documentation to refer to the process of controlling other applications through COM.

The term "ActiveX" is also often used when discussing COM objects. ActiveX objects are special types of COM objects, some can be used with the CreateObject or GetObject functions and some cannot - check the documentation for the ActiveX software for details. Visual Basic programmers should know that they can create COM applications to integrate with Active Call Center by creating ActiveX DLL and ActiveX EXE projects.

Some applications that support COM interfaces are:

The CreateObject and GetObject functions are used to latch on to the COM interfaces of other applications. The functions and their usage is documented in Microsoft's VBScript documentation, we provide an example below that shows how to use CreateObject from an Active Call Center macro to interface with Microsoft Excel to open a workbook:

' Define an object for MSExcel and a generic string
Dim xl
' Create MS Excel object.
Set xl = CreateObject("Excel.Application")
' Show Excel.
xl.Visible = True
' Open the file.
xl.Workbooks.Open "C:\test.xls"

There are lots of example Call Trees provided that show how to use COM interfaces on a variety of different applications. Study these Call Trees carefully, since using the CreateObject / GetObject functions is a critical part of integrating Active Call Center with other products.

CreateObject vs. GetObject: What's the Difference?

Besides minor differences in the syntax, the CreateObject and GetObject functions are used in different contexts. The differences are discussed in the VBScript documentation, but can be summarized as follows:

Finding Constant Values not Defined in VBScript

Many COM applications include constant values that are used to simplify their interfaces. For example, Microsoft Excel includes constants like xlYes and xlNo to make code that uses the Microsoft Excel COM objects easier to read. Visual Basic (VB) and Visual Basic for Applications (VBA) developers know that these constants can be used "as is" in their code. Unfortunately, this is not the case with VBScript.

Application integration with VBScript is slightly more challenging than accomplishing the same tasks in VB/VBA. VB and VBA load the many constant values that are relevant to the objects being used, but VBScript cannot load these values. Much of the documentation for COM applications uses the names of the constants without showing the values of the constants. Since these constants are not defined in VBScript, it is important to be able to locate and define their values for use with VBScript.

We will now present a technique that can be used to locate constant values required to do application integration in VBScript. Consider an example in which Excel VBA code is used to integrate Microsoft Outlook into Microsoft Excel. This code may look something like (note long lines may run over without the underscore line extension):

' Define variables for MS Outlook objects
Dim olook, olookNameSpace, olookEMailFolder
' Get Outlook application object - Outlook must be open!
Set olook = GetObject("","Outlook.Application")
' Get MAPI name space
Set olookNameSpace = olook.GetNameSpace("MAPI")
' Get the EMail Folder.
Set olookEMailFolder = _

olookNameSpace.GetDefaultFolder(olFolderInbox)

On the last line, the constant "olFolderInbox" is used to identify the Inbox folder. Although VBA knows what this constant means, VBScript will not know understand "olFolderInbox" since it has not been defined in this script. To correct the code so that it runs under VBScript, we must locate the value of olFolderInbox.

The easiest way to locate the value of olFolderInbox is to start the VBA application: Excel in the example above. The basic steps required to locate the value of the "olFolderInbox" constant with Excel 97 or 2000 are as follows (the exact instructions may vary depending on the specific circumstances):

Start the VBA editor in Excel by pressing ALT-F11, then choose Tools... References from the Excel VBA menu bar.

Find the Microsoft Outlook object library and check it off on the list. Click OK.

Press F2 to launch the object browser.

From the dropdown menu up top, select the Outlook object library.

In the left pane of the object browser, click globals which should be at the top of the list.

In the right pane of the object browser, locate the value olFolderInbox and click on it.

Look at the value of this constant in the bottom pane of the object browser and notice that it is 6.

Since olFolderInbox = 6, the VBScript compatible version of the code above would have the last line read:

Set olookEMailFolder = _
olookNameSpace.GetDefaultFolder(6)

Another solution is to define the constant by adding the lines

Dim olFolderInbox
olFolderInbox = 6

at the top of the script and leave the last line of the macro the same.

Use VB/VBA to Speed Complex Integration Tasks

It's often much easier to write complex application integration code in VB or VBA and then port to VBScript vs. trying to write the code in VBScript beginning to end. When writing code outside of the VBScript environment, be sure to keep in mind the differences between VB/VBA and VBScript. Some tips:

See Also

VBScript Macros

Learning VBScript

VBScript Resources

Variables Used in Macros

Integrating Other Applications

Testing and Debugging VBScript Macros

VBScript Built-In Functions (Global Functions)

Automating Windows Tasks

Call Ending VBScript Macro