Syntax |
CreateObject(class$) |
Description |
Creates an OLE automation object and returns a reference to that object. |
Comments |
The class$ parameter specifies the application used to create the object and the type of object being created. It uses the following syntax: "application.class", where application is the application used to create the object and class is the type of the object to create. At runtime, CreateObject looks for the given application and runs that application if found. Once the object is created, its properties and methods can be accessed using the dot syntax (e.g., object.property = value). There may be a slight delay when an automation server is loaded (this depends on the speed with which a server can be loaded from disk). This delay is reduced if an instance of the automation server is already loaded. |
Examples |
This first example instantiates Microsoft Excel. It then uses the resulting object to make Excel visible and then close Excel. Sub Main() Dim Excel As Object On Error GoTo Trap1 'Set error trap. Set Excel =
CreateObject("excel.application"'Instantiate object. Exit Sub 'Exit before error trap. Trap1: MsgBox "Can't create Excel
object." 'Display error message. |
|
This second example uses CreateObject to instantiate a Visio object. It then uses the resulting object to create a new document. Sub Main() Dim Visio As Object On Error Goto NO_VISIO Set Visio =
CreateObject("visio.application")'Create Visio object. Set doc = Visio.Documents.Add("") 'Create a new document. Set page =
doc.Pages(1) 'Get first page. |
See Also |
C |