Application.CreateItemFromTemplate Method (Outlook)
Creates a new Microsoft Outlook item from an Outlook template (.oft) and returns the new item.
Syntax
expression .CreateItemFromTemplate(TemplatePath, InFolder)
expression A variable that represents an Application object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
TemplatePath |
Required |
String |
The path and file name of the Outlook template for the new item. |
InFolder |
Optional |
Variant |
The folder in which the item is to be created. If this argument is omitted, the default folder for the item type will be used. |
Return Value
An Object value that represents the new Outlook item.
Remarks
New items will always open in compose mode, as opposed to read mode, regardless of the mode in which the items were saved to disk.
Example
This Visual Basic for Applications (VBA) example uses CreateItemFromTemplate to create a new item from an Outlook template and then displays it. The CreateTemplate macro shows you how to create the template that is used in the first example. To avoid errors, replace 'Dan Wilson' with a valid name in your address book.
Sub CreateFromTemplate()
Dim MyItem As Outlook.MailItem
Set MyItem = Application.CreateItemFromTemplate("C:\statusrep.oft")
MyItem.Display
End Sub
Sub CreateTemplate()
Dim MyItem As Outlook.MailItem
Set MyItem = Application.CreateItem(olMailItem)
MyItem.Subject = "Status Report"
MyItem.To = "Dan Wilson"
MyItem.Display
MyItem.SaveAs "C:\statusrep.oft", OlSaveAsType.olTemplate
End Sub
The following Visual Basic for Applications (VBA) example shows how to use the optional InFolder parameter when calling the CreateItemFromTemplate method.
Sub CreateFromTemplate2()
Dim MyItem As Outlook.MailItem
Set MyItem = Application.CreateItemFromTemplate("C:\statusrep.oft", _
Application.Session.GetDefaultFolder(olFolderDrafts))
MyItem.Save
End Sub