Description:
Creates and returns an Automation object.
Syntax:
Object CreateObject(Variant class)
Parameters:
class | (Variant) uses the syntax ServerName.TypeName:
ServerName - The name of the application providing the object
TypeName - The type or class of the object to create |
---|
Note:
Automation servers provide at least one type of the object. For example, a word-processing application may provide an
application object, a
Document object and a
Toolbar object.
To create an Automation object, assign the object returned by
CreateObject to an object variable:
Set oExcel = CreateObject("Excel.Sheet")
This script starts the application that creates the object (in this case a
Microsoft Excel spreadsheet). Once an object is created, you refer to it in the script using the object variable you defined.
Example1:
Creates the Test.xls file by means of EXCEL program
VBScriptSelect and copy to clipboard
Dim oExcelApp, oWorkbook, oSheet
Set oExcelApp = CreateObject("Excel.Application")
oExcelApp.Visible = true
Set oWorkbook = oExcelApp.WorkBooks.Add
Set oSheet = oExcelApp.Sheets(1)
oSheet.Cells(1, 1) = oWorkbook.Sheets.Count
oSheet.Cells(1, 2) = 34
oSheet.Cells(2, 1) = Now()
oSheet.SaveAs "C:\Data\Test.xls"
oExcelApp.Quit
Example2:
Creates the Test.doc file by means of WORD program
VBScriptSelect and copy to clipboard
Dim oWord
Set oWord = CreateObject("Word.Basic")
oWord.AppShow
oWord.FileOpen "C:\Data\Test.doc"
oWord.Insert "" & vbNewLine
oWord.Insert "Temperature=" & pMe.Pm("/Kogen/Temp").Value & " °C " & vbNewLine
oWord.FileSave