Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel VB Language Reference > Siebel VB Language Reference >
CreateObject Function
Creates a new COM automation object.
Syntax
CreateObject(application.objectname)
Argument Description application The name of the application objectname The name of the object to be usedReturns
Not applicable
Usage
To create an object, you first must declare an object variable, using Dim, and then Set the variable equal to the new object, as follows:
Dim excelObj As Object
Set excelObj = CreateObject("Excel.Application")To refer to a method or property of the newly created object, use the syntax objectvar.property or objectvar.method, as follows:
Dim cellVal as String
cellVal = excelObj.ActiveSheet.Cells(1,1).ValueRefer to the documentation provided with your Web Client Automation Server application for correct application and object names. Modal or nonmodal forms cannot be displayed from server-based applications. DLLs instantiated by this function should be Thread-Safe.
CAUTION: When invoking a COM object, a 440 error message may occur if you pass the wrong number, order, or type of parameters to the COM object.
Example
This example uses CreateObject to create an Excel worksheet and then edits and saves the worksheet.
Sub BtnExcel_Click
Dim oWorkSheet As Object
Dim sfileName As String
Set oWorkSheet = CreateObject("Excel.Sheet")
If oWorkSheet Is Nothing the
Exit Sub
End If' Make Excel visible through the Application object.
oWorkSheet.Application.Visible = 1
' Place some text in the first cell of the sheet
oWorkSheet.ActiveSheet.Cells(1,1).Value = "Column A, Row 1"
' Save the sheet
sfileName = "C:\demo.xls"
oWorkSheet.SaveAs (fileName)
' Close Excel with the Quit method on the Application object
oWorkSheet.Application.Quit
' Clear the object from memory
Set oWorkSheet = Nothing
End SubThis example uses CreateObject to create a Word document and then edits and saves the document.
Sub BtnWrd_Click
Dim oWord As Object
Dim fileName As String
fileName = "C:\demo.doc"
Set oWord = CreateObject("Word.Application")
' Create a new document
oWord.Documents.Add
If oWord Is Nothing then
Exit Sub
End If
' Make Word visible through the Application object
oWord.Application.Visible = 1
' Add some text
oWord.Selection.TypeText "This is a demo."
' Save the document
oWord.ActiveDocument.SaveAs (fileName)
' Close Word with the Quit method on the Application object
oWord.Quit
' Clear the object from memory
Set oWord = Nothing
End SubSee Also
GetObject Function
Is Operator
Me
New Operator
Nothing Function
Object Class
Typeof Function
Bookshelf Home | Contents | Index | Search | PDF | ![]() ![]() ![]() ![]() |
Siebel VB Language Reference Published: 18 June 2003 |