VBS Tutorial: function-CreateObject Function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.