CreateObject Method

Microsoft Outlook Visual Basic

Show All

CreateObject Method

       

Creates an Automation object of the specified class. If the application is already running, CreateObject will create a new instance.

This method is provided so that other applications can be automated from VBScript. It should not be used to automate Outlook from VBScript.

Note  The CreateObject methods commonly used in the example code within this Help file (available when you click "Example") are made available by Microsoft Visual Basic (VB) or Microsoft Visual Basic for Applications. These examples do not use the same CreateObject method that is implemented as part of Outlook's object model.

expression.CreateObject(ObjectName)

expression   Required. An expression that returns an Application object.

ObjectName   Required String. The class name of the object to create. For information about valid class names, see OLE Programmatic Identifiers.

Example

This VBScript example utilizes the Open event of the item to access Microsoft Internet Explorer and display the Microsoft Web page.

Sub Item_Open()
   Set Web = CreateObject("InternetExplorer.Application")
   Web.Visible = TRUE
   Web.Navigate "www.microsoft.com"
End Sub

This VBScript example utilizes the Click event of a CommandButton control on the item to access Microsoft Word and open a document on the root directory named "Resume.doc".

Sub CommandButton1_Click()
    Set Word = CreateObject("Word.Application")
    Word.Visible = TRUE
    Word.Documents.Open("C:\Resume.doc")
End Sub