简体   繁体   English

如何使用 Excel VBA 打开 Outlook 电子邮件模板?

[英]How to open an Outlook email template with Excel VBA?

I am trying to open an Outlook 2010 email template with Excel.我正在尝试使用 Excel 打开 Outlook 2010 电子邮件模板。 I get the following error:我收到以下错误:

"Run-time error '-2147287038 (80030002)': “运行时错误‘-2147287038 (80030002)’:
Cannot open file:不能打开文件:
C:\\My\\Path\\MyTemplate.oft. 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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