CitectVBA Programming Reference > Understanding CitectVBA Language Basics > OLE Services > Assigning references to OLE automation objects

Assigning references to OLE automation objects

An OLE Automation object MUST be defined before it can be used. Once defined (see Declaration of OLE Automation objects in CitectVBA), you assign an OLE Automation reference to the object variable in CitectVBA using the CitectVBA CreateObject function within a CitectVBA Set statement in the following syntax:

Set <objVarName> = CreateObject(<objClassName>)

where:

The object class name passed as the argument to the CreatObject function usually consists of the fully qualified class name of the object being created, for example "Word.Application" or "Excel.Application".

Example

' create variable to store object reference
Dim objExcelApp As Object
' create the app object and assign the reference
Set objExcelApp = CreateObject("Excel.Application")
' or
' create variable to store object reference
Dim objWordApp As Object
' create the app object and assign the reference
Set objWordApp = CreateObject("Word.Application")

Once assigned, you can then use that object variable in your CitectVBA code to manipulate the referenced object model. See Using OLE automation objects.

Dependant objects (which cannot be created independantly) can be "drilled-down" to and subsequently assigned from existing (externally creatable) independant object s, by using a method of the higher level object. See Understanding object models in OLE Automation.

For examples of independant objects, Microsoft Excel provides the "Excel.Application", "Excel.Sheet ", and "Excel.Chart" externally creatable objects amongst others, (two of which are demonstrated in OLE Automation example using the Microsoft Excel object), and Microsoft Word provides the "Word.Application", "Word.Document", and "Word.Picture" externally creatable objects amongst others (and is demonstrated in OLE Automation example using the Microsoft Word object).

See Also

OLE automation objects