CreateItem Method

Microsoft Outlook Visual Basic

Creates a new Microsoft Outlook item and returns it. The CreateItem method can only create default Outlook items. To create new items using a custom form, use the Add method on the Items collection.

expression.CreateItem(ItemType)

expression    Required. An expression that returns an Application object.

ItemType    Required OlItemType. The Outlook item Type for the new item.

OlItemType can be one of these OlItemType constants.
olAppointmentItem
olContactItem
olDistributionListItem
olJournalItem
olMailItem
olNoteItem
olPostItem
olTaskItem

Example

The following Microsoft Visual Basic/Visual Basic for Applications (VBA) example creates a new MailItem object and sets the BodyFormat property to olFormatHTML. The Body text of the e-mail item will now appear in HTML format.

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Please enter the message text here. </BODY></HTML>"
       .Display
    End With

End Sub
		

If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to create a contact item in the default Contacts folder using VBScript code.

Sub CommandButton1_Click()
 Set myNameSpace = Application.GetNameSpace("MAPI")
 Set myFolder = myNameSpace.GetDefaultFolder(10)
 Set myItem = Application.CreateItem(2)
 myItem.Display
End Sub