Automation Objects

Automation objects are special objects that applications (called automation servers) make available to other applications. The objects make it possible for functionality or data within one application to be used inside the other application, for example, a spreadsheet within a word processing document. This is convenient for application users because they do not need to leave one application in order to use the other application.

Automation servers provide at least one type of object. For example, a word processing application might provide an application object, a document object, and a toolbar object. Automation objects can be created with the Windows client applications of Meridian with VBScript. To create an automation object, assign the object returned by CreateObject to an object variable as in the following example:

Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")

This code starts the application and creates the object (in this example, a Microsoft Excel worksheet). After an object is created, refer to it in your code using the object variable you defined. As shown in the following example, you can access properties and methods of the new object using the object variable created above, ExcelSheet, and other Excel objects, including the Application object and the ActiveSheet.Cells collection:

' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
' Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"
' Save the sheet.
ExcelSheet.SaveAs "C:\DOCS\TEST.XLS"
' Close Excel with the Quit method of the Application object.
ExcelSheet.Application.Quit
' Release the object variable.
Set ExcelSheet = Nothing

By default, automation objects are created on the computer where the code is executed. You can create an object on a remote networked computer by passing the name of the computer to the ServerName argument of CreateObject. In addition, you can specify ServerName using DNS format or an IP address. The following code returns the version number of Excel running on a remote network computer named MyServer:

Function GetVersion

Dim XLApp

    Set XLApp = CreateObject("Excel.Application", "MyServer")
    GetVersion = XLApp.Version

End Function

An error occurs if the specified remote computer does not exist or cannot be found, for example, because of security restrictions.

Note:

CreateObject is suitable for creating automation objects that do not act upon Meridian objects. For access to Meridian objects, use the AMCreateObject Function instead, which works the same as CreateObject but also passes the current Repository object to the IAMCommandSetInitialize interface of the automation server.

The following example defines a procedure for a custom command that creates a Connection object to connect to an Access database, creates a Recordset object to hold data from the connection, and sets a document property to a value from the Recordset object:

Sub ReadSettings_Execute(Batch)
 
    Dim cn, rs

    Set cn = CreateObject ("ADODB.Connection")
    Set rs = CreateObject ("ADODB.Recordset")
    
    cn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\test.mdb;Persist Security Info=False"

    cn.Open
    rs.Open "SELECT * FROM Address", cn
    
    Document.Test = rs.Fields(1).Value
    
    rs.Close
    cn.Close     Set rs = Nothing
    Set cn = Nothing
    
End Sub

2022 R2