尝试使用 Excel VBA 打开 Outlook 电子邮件模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25829685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to open an Outlook email template with excel VBA
提问by David Elphee
I am trying to open an Outlook 2010 email template with Excel. I get the following error:
我正在尝试使用 Excel 打开 Outlook 2010 电子邮件模板。我收到以下错误:
"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."
“运行时错误'-2147287038 (80030002)':无法打开文件:C:\My\Path\MyTemplate.oft。该文件可能不存在,您可能没有打开它的权限,或者它可能在另一个程序。右键单击包含该文件的文件夹,然后单击“属性”以检查您对该文件夹的权限。”
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!!!
感谢您的任何帮助!!!
回答by niton
"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 ElpheeSep 14 '14 at 13:23"
“我在另一台计算机上尝试了我的代码并且它起作用了。我回去更改了模板的文件名,因为以前的名称都是大写的(应该没关系,对吧?)我收到一条消息,说需要成为执行此操作的管理员,我认为这很奇怪,因为这是我的个人家用计算机。但是,当我单击“继续”时,它会继续并更改名称。现在它可以工作了 。– David Elphee 2014 年9 月 14 日 13 点: 23"