Home » excel » Trying to open an Outlook email template with excel VBA

Trying to open an Outlook email template with excel VBA

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am trying to open an Outlook 2010 email template with Excel. I get the following error:

“Run-time error ‘-2147287038 (80030002)’:
Cannot open file:
C:\My\Path\MyTemplate.oft. The file may not exist, you may not have permission to open it, or it may be open in another program. Right-click the folder that contains the file, and then click Properties to check your permissions for the folder.”

The file exists (in the right place), I have checked permissions (as far as I know how), and the file is not already open.

Here is my code:

    Sub Mail_experiment()
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.mailitem
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate("C:\My\Path\MyTemplate.oft")
    On Error Resume Next
    With OutMail
        .to = "[email protected]"
        .CC = ""
        .BCC = ""
        .Subject = "This is my Subject line"
        .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
    End Sub

Thank you for any help!!!

How to&Answers:

“I tried my code on a different computer and it worked. I went back and changed the file name of my template, as the previous name was in all capitals (shouldn’t matter, right?). I got a message about needing to be an administrator to do this, which I thought was strange since this is my personal home computer. However, when I clicked “continue” it went ahead and changed the name. Now it works. – David Elphee Sep 14 ’14 at 13:23″