CreateItemFromTemplate Method
Creates a new Microsoft Outlook item from an Outlook template (.oft) and returns the new item.
expression**.CreateItemFromTemplate(TemplatePath**, InFolder)
*expression * Required. An expression that returns an Application object.
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.
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 myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("C:\statusrep.oft")
MyItem.Display
End Sub
Sub CreateTemplate()
Dim myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItem(olMailItem)
MyItem.Subject = "Status Report"
MyItem.To = "Dan Wilson"
MyItem.Display
MyItem.SaveAs "C:\statusrep.oft", OlSaveAsType.olTemplate
End Sub
If you use Microsoft Visual Basic Scripting Edition (VBScript) in an Outlook form, you do not create the Application object. This example shows how to perform the same task using VBScript code.
Sub CommandButton1_Click()
Set myItem = Application.CreateItemFromTemplate _
("C:\Program Files\Microsoft Office\Templates\Outlook\While You Were Out.oft")
myItem.Display
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 myOlApp As Outlook.Application
Dim MyItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("C:\statusrep.oft", _
myOlApp.Session.GetDefaultFolder(olFolderDrafts))
MyItem.Save
End Sub
Applies to | Application Object
See Also | CreateItem Method