CreateObject Function

See Also22WV053

Creates an OLE Automation object.

Syntax

CreateObject (class)

Remarks

The class argument is a string indicating the name of the application used to create the object and the type of object.  To specify an object's class, use the following syntax:

 

"appname.objecttype"

 

The class argument has these parts:

Part               Description

 

appname        The name of the application providing the object.

objecttype      The type, or class, of object to create.

 

 

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.

 

Note   To get a list of OLE Automation objects an application supports, consult that application's documentation.

 

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

Dim MyObject As Object
Set MyObject = CreateObject("WordProc.Document")

 

When this code is executed, the application creating the object is started if it is not already running (WordProc.Exe in this example), and an object of the specified type is created.  Unlike creating a linked or embedded object using the OLE control, the object's image is not displayed anywhere in Visual Basic, nor is the object's data maintained by Visual Basic.

Once an object is created, you reference it in Visual Basic code using the object variable you defined.  In the above example you access properties and methods of the new object using the object variable, MyObject.  For example:

MyObject.Bold
MyObject.Insert "Hello, world."
MyObject.Print
MyObject.SaveAs "C:\WORDPROC\DOCS\TEST.DOC"


See Also

Help:

GetObject FunctionTLKUVF

Object Property1MHI551

OLE Automation1J3AYU5

OLE Control2HQDVVU

Set StatementLANSET

 

Programmer's Guide:

Chapter 23, "Programming Other Applications' Objects"