Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Assigning References to OLE Automation Objects

  • Last UpdatedJul 18, 2023
  • 2 minute read

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

Set <objVarName> = CreateObject(<objClassName>)

Where:

  • Set is the required reference assignment statement keyword

  • <objVarName> represents the required name of the variable receiving the reference

  • CreateObject() function creates the object of the class type specified in the argument

  • <objClassName> represents the required name of the class providing the object

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 VBA 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

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in