使用Excel VBA通​​过模板在Outlook 2010中创建电子邮件 [英] Using Excel VBA to create email in Outlook 2010 from template

查看:130
本文介绍了使用Excel VBA通​​过模板在Outlook 2010中创建电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在XP上的Excel/Outlook 2003中运行良好,现在正在运行Windows 7 Excel/Outlook 2010,并收到错误消息:

运行时错误'287':应用程序定义的错误或对象定义的错误.

我的代码基于以下答案: 从Excel 2007发送电子邮件使用Outlook模板&的VBA设置变量

我正在创建Outlook对象和mailitem,如下所示:

Dim MyOlApp
Dim MyOlItem
Set MyOlApp = CreateObject("Outlook.Application")
Set MyOlItem = MyOlApp.CreateItemFromTemplate(Range("oftLocation").Value) 'user defined location

我引用MyOlItem后出现错误,代码正在替换.htmlBody

中的引用

修改.Body没什么区别,显示相同的错误.

我在VBA中的引用设置为:

  • VBA
  • Microsoft Excel 14.0对象库
  • OLE自动化
  • Microsoft Office 14.0对象库
  • Microsoft Forms 2.0对象库
  • Microsoft脚本运行时

解决方案

这还不是答案,但我想收集评论中正在发生的事情,因为我认为这是迄今为止所见最好的方向. /p>

我已经测试了您所提问题中的代码,并且使用Outlook 2010和Excel 2010对我来说也很好.

当Excel尝试与Outlook进行交互时,Programmatic Access设置将发挥作用.

我相信,如果您的AntiVirus已过时,它们会设置为警告状态.这类似于Windows检测AntiVirus状态的方式.因此,当您从Excel访问Outlook时,通常会出现一个提示,要求获得许可g.就我而言,在正常情况下,您将允许该操作,并且代码将照常进行.

但是,我看到人们发现错误287的原因是用户在该提示下单击否.对于您来说,这不是出现的情况.您需要仔细查看与Programmatic Access有关的Outlook中的信任中心"设置.与防病毒软件有交互作用,信任中心也将提供一些信息.如果您未使用管理员权限运行Outlook,则将禁用该设置.让我知道你的想法.

到目前为止,我还没有明确表态,但我也想引起您对AV的注意.这是它试图停止的事情之一.也许有一个被炒鱿鱼的规则阻止了这种情况.

无论哪种方式,您都应该能够在另一个环境中进行测试,以查看它是否特别是您的系统.我想我们都同意这不是专门的代码,因为我知道它可以在其他地方使用.

I have code that worked well in Excel/Outlook 2003 on XP, I'm now running Windows 7 Excel/Outlook 2010 and receive an error:

Run-time error '287': Application-defined or object-defined error.

My code is based on this answer in: Send an email from Excel 2007 VBA using an Outlook Template & Set Variables

I'm creating my outlook object and mailitem like this:

Dim MyOlApp
Dim MyOlItem
Set MyOlApp = CreateObject("Outlook.Application")
Set MyOlItem = MyOlApp.CreateItemFromTemplate(Range("oftLocation").Value) 'user defined location

The error appears after I reference MyOlItem, the code is replacing references in the .htmlBody

Amending to .Body makes no difference, same error shows.

My references in VBA are set to:

  • VBA
  • Microsoft Excel 14.0 Object Library
  • OLE Automation
  • Microsoft Office 14.0 Object Library
  • Microsoft Forms 2.0 Object Library
  • Microsoft Scripting Runtime

解决方案

This isnt an answer yet but I want to collect what is happening in the comments since I feel this is the best direction with what I have seen thus far.

I have tested the code in you have in your question and it works just fine for me using Outlook 2010 and Excel 2010.

When Excel tries to interact with Outlook the Programmatic Access settings come into play.

I beleive they are setting to a warning state if you AntiVirus is out of date. This is similar to the way that Windows detects the status of your AntiVirus. So when you access Outlook from Excel normally get a prompt asking permissiong for the action. In my case, and your under normal circumstances, you would allow the action and the code would proceed as normal.

However I have seen people catch error 287 with the logic that the user hit No to that prompt. This does not appear to be the case for you. You need to take a good look at your Trust Center settings in Outlook where Programmatic Access in concerned. There is interaction with antivirus and the Trust Center will provide some information as well. Settings there will be disabled if you are not running Outlook with administrator rights. Let me know what you come up with.

I havent been explicit up until now but I would like to draw attention to your AV as well. This is one of the things that it would try to stop. Perhaps there is a rule that fired that is preventing this.

Either way you should be able to test this in another environment to see if it maybe your system in particular. I think we both agree it is not the code specifically since I know it works elsewhere.

这篇关于使用Excel VBA通​​过模板在Outlook 2010中创建电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆