CreateObject Function

Description

Creates an OLE Automation object.

Syntax

CreateObject(class)

The class named argument uses the syntax: "appname.objecttype" and has these parts:

Part

Description

appname

The name of the application providing the object.

objecttype

The type or class of object to create.


Remarks

Note

If an application that supports OLE Automation exposes an object library, it is preferable to use the functions defined within the library for object creation rather than use CreateObject.

Each application that supports OLE Automation provides at least one type of object. For example, a word processing application may provide an application object, a document object, and a toolbar object.

Use this function to create an OLE Automation object and assign the object to an object variable. To do this, use the Set statement to assign the object returned by CreateObject to the object variable. For example:


Set WordBasicObject = CreateObject("Word.Basic")

When this code is executed, the application creating the object is started, if it is not already running (Microsoft Word in this example), and an object of the specified type is created. Once an object is created, you reference it in code using the object variable you defined. In the above example, you access properties and methods of the new object using the object variable, WordBasicObject. For example:


WordBasicObject.Insert "Hello, world."
WordBasicObject.FilePrint
WordBasicObject.FileSaveAs "C:\DOCS\TEST.DOC"

See Also

GetObject Function, Set Statement.