CreateObject Function
Description
Creates and returns a reference to an OLE Automation Object.
Syntax
CreateObject(class)The class argument uses the syntax "servername.typename" described as follows:
Part Description servername The name of the application providing the object. typename The type or class of the object to create. Remarks
OLE Automation servers provide at least one type of object. For example, a word-processing application may provide an application object, a document object, and a toolbar object.To create an OLE Automation object, assign the object returned by CreateObject to an object variable:
This code starts the application creating the object (a Microsoft Excel spreadsheet in this case.) Once and object is created, you reference it in code using the object variable you defined. In this example, you access properties and methods of the new object using the object variable, ExcelSheet and other Excel objects, including the Application object and the Cells collection. For example:Dim ExcelSheet Set ExcelSheet = CreateObject("Excel.Sheet")
' Make Excel visible through the Application object. ExcelSheet.Application.Visible - True ' Place some text in the first cell of the sheet. ExcelSheet.Cells(1,1).Value = "This is column A, row 1" ' Save the sheet. ExcelSheet.SaveAs "C:\DOCS\TEST.DOC" ' Close Excel with the Quit method on the Application object. ExcelSheet.Application.Quit ' Release the object variable. Set ExcelSheet = Nothing
Note For security reasons, CreateObject is not available in all VBScript hosts, e.g., it is not available in the Microsoft Internet Explorer.