简体   繁体   中英

How to open an Outlook email template with Excel VBA?

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 checked permissions (as far as I know how), and the file is not open.

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 = "myEmail@aol.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is my Subject line"
        .Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

“我在另一台计算机上尝试了我的代码并且它起作用了。我回去更改了模板的文件名,因为以前的名称都是大写的(应该没关系,对吧?)我收到一条消息,说需要成为执行此操作的管理员,我认为这很奇怪,因为这是我的个人家用计算机。但是,当我单击“继续”时,它会继续并更改名称。现在它可以工作了。– David Elphee 2014 年9 月 14 日 13 点: 23"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM