INFO: OLE Automation Objects with GetObject and CreateObject

ID: Q114347

The information in this article applies to:

SUMMARY

This article documents the behavior of top-level Microsoft OLE Automation objects in Microsoft Word, Microsoft Excel, and Microsoft Project when manipulated by the Visual Basic CreateObject() and GetObject() functions.

Because only the products and versions listed at the beginning of this article support OLE 2.0 Automation, the version-dependent top-level OLE Automation objects, such as Excel.Application.5, function the same way as the version-independent top-level OLE automation objects such as Excel.Application. Therefore, only the version-independent top-level OLE Automation objects are discussed in this article.

In addition, this article does not discuss the possibility of other applications referencing the same objects or the possibility of running out of resources or memory.

MORE INFORMATION

Each Microsoft application that currently supports OLE Automation behaves differently with respect to how its top-level OLE Automation objects function. The following sections list the behaviors of each application and each possible syntax used with each top-level OLE Automation objects within that application.

Microsoft Excel Versions 5.0 & 7.0

Syntax Statements for Microsoft Excel Versions 5.0 & 7.0 Application Object

Set Obj = CreateObject("Excel.Application")

Set Obj = GetObject("", "Excel.Application") Set Obj = GetObject(, "Excel.Application")

Syntax Statements for Microsoft Excel Versions 5.0 & 7.0 Sheet Object

Set Obj = CreateObject("Excel.Sheet")

Set Obj = GetObject("", "Excel.Sheet") Set Obj = GetObject(, "Excel.Sheet") Set Obj = GetObject("C:\BOOK.XLS", "Excel.Sheet")

Syntax Statements for Microsoft Excel Versions 5.0 & 7.0 Chart Object

Set Obj = CreateObject("Excel.Chart")

Set Obj = GetObject("", "Excel.Chart") Set Obj = GetObject(, "Excel.Chart") Set Obj = GetObject("C:\BOOK.XLS", "Excel.Chart")

Microsoft Word Version 6.0

Syntax Statements for Microsoft Word Version 6.0 Basic Object

Set Obj = CreateObject("Word.Basic")

Set Obj = GetObject("", "Word.Basic") Set Obj = GetObject(, "Word.Basic")

Microsoft Word Version 7.0

Syntax Statements for Microsoft Word Version 7.0 Basic Object

Set Obj = CreateObject("Word.Basic")

Set Obj = GetObject("", "Word.Basic") Set Obj = GetObject(, "Word.Basic")

Microsoft Project Versions 4.0 & 4.1

Syntax Statements for Microsoft Project Versions 4.0 & 4.1 Application Object

Set Obj = CreateObject("MSProject.Application")

Set Obj = GetObject("", "MSProject.Application") Set Obj = GetObject(, "MSProject.Application")

Syntax Statements for Microsoft Project Versions 4.0 & 4.1 Project Object

Set Obj = CreateObject("MSProject.Project")

Set Obj = GetObject("", "MSProject.Project") Set Obj = GetObject(, "MSProject.Project") Set Obj = GetObject("C:\PROJ.MPP", "MSProject.Project") NOTE: When an object variable goes out of scope, it is de-referenced. The object reference count is de-cremented, and if it reaches zero, the object can be removed from memory. You can explicitly de-reference an object by setting it to nothing (Set Obj = Nothing). This should have the same effect as the object variable going out of scope.

Additional query words: W_VBApp

Keywords          : kbprg kbVBp400 IAPOLE VB4WIN vbwin 
Version           : WINDOWS:3.0 4.0
Platform          : WINDOWS
Issue type        : kbinfo

Last Reviewed: October 1, 1997