CreateObject Function
Create and return the reference to the Automation Object.
CreateObject(servername.typename [, location])
Parameters
Servername
Required. Provide the application name of the object.
Typename
Required. The object type or class to be created.
Location
Optional. The network server where the object is located will be created.
Description
The Automation server provides at least one object type. For example, a word processing application can provide application objects, document objects, and toolbar objects.
To create an Automation Object, SetCreateObjectThe object returned by the function is assigned to an object variable:
Dim ExcelSheetSet ExcelSheet = CreateObject("Excel.Sheet")
The above code starts the application that creates an object (in this instance, it is a Microsoft Excel spreadsheet. After an object is created, you can use the defined object variable in the code to reference this object. In the following example, you can use object variables, ExcelSheet, and other Excel objects, including the Application Object and Cells set to access the attributes and methods of the new object. For example:
' 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 on the Application object.ExcelSheet.Application.Quit' Release the object variable.Set ExcelSheet = Nothing
Create an object on the remote server. It can only be completed when Internet security is disabled. Pass the computer nameCreateObjectServer name parameter. You can create an object on a remote network. The name is like the name of the machine in the shared part. For example, the Network Share Name is "\ myserver \ public ",ServernameIs "myserver ". In addition, you can only specifyServernameUse DNS format or IP address.
Run the following code to return the Excel instance version number on a remote network computer named "myserver:
Function GetVersion Dim XLApp Set XLApp = CreateObject("Excel.Application", "MyServer") GetVersion = XLApp.VersionEnd Function
The error occurs when the specified remote server does not exist or cannot be found.