Office 365 proplus

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
i have this code for template when run get

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]
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top