i have this code for template when run get
error we cannot opened, and highlight this line of the code:
complete code:
error we cannot opened, and highlight this line of the code:
Code:
Set oMail = Application.CreateItemFromTemplate(strTemplate)
complete code:
Code:
[COLOR=#444444]Public lstNum As Long[/COLOR]
Public Sub ChooseTemplate()
Dim oMail As Outlook.MailItem
Dim oContact As Outlook.ContactItem
If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then
Set oContact = ActiveExplorer.Selection.Item(1)
Dim strTemplate As String
UserForm1.Show
Select Case lstNum
Case -1
' -1 is what you want to use if nothing is selected
strTemplate = "template-1"
Case 0
strTemplate = "template-1"
Case 1
strTemplate = "template-2"
Case 2
strTemplate = "template-3"
Case 3
strTemplate = "template-4"
Case 4
strTemplate = "template-5"
End Select
strTemplate = "C:\Users\me\Templates\" & strTemplate & ".oft"
Set oMail = Application.CreateItemFromTemplate(strTemplate)
With oMail
.To = oContact.Email1Address
.ReadReceiptRequested = True
.Subject = "My Macro test"
.Body = "Hi " & oContact.FirstName & "," & vbCrLf & vbCrLf & oMail.Body
.Display
End With
End If
Set oMail = Nothing
[COLOR=#444444]End Sub[/COLOR]