使用 VBA 禁用 Outlook 安全设置
我正在尝试使用宏中的 VBA 自动通过电子邮件发送报告。该报告是由outlook2007从Access2007发送的。发送报告时,我从 Outlook 收到一条安全消息,提示“某个程序正在尝试访问您的地址簿或联系人”或“某个程序正在尝试访问您存储在 Outlook 中的电子邮件地址...”。这条消息对我来说是一个问题,因为我想使用 Windows 任务计划程序自动发送报告,而无需任何人工交互。所以我想禁用此安全通知。我在谷歌上搜索,这是我到目前为止的代码,但给了我错误,我不知道我还应该做什么。提前感谢您的帮助。我是一名初学者程序员。错误是
Public Sub Send_Report()
Dim strRecipient As String
Dim strSubject As String
Dim strMessageBody As String
Dim outlookapp As Outlook.Application
Set outlookapp = CreateObject("Outlook.Application")
OlSecurityManager.ConnectTo outlookapp 'error is here says object required
OlSecurityManager.DisableOOMWarnings = True
On Error GoTo Finally
strRecipient = "[email protected]"
strSubject = "Tile of report"
strMessageBody = "Here is the message."
DoCmd.SendObject acSendReport, "Report_Name", acFormatPDF, strRecipient, , , strSubject, strMessageBody, False
Finally:
OlSecurityManager.DisableOOMWarnings = False
End Sub
I am trying to auto email a report from access using VBA in a macro. The report is sent from Access2007 by outlook2007. When the report is being sent, I get a security message from outlook saying "a program is trying to access your Address book or Contacts" or "a program is trying to access e-mail addresses you have stored in Outlook..." . This message is a problematic for me because I want to use windows task scheduler to automatically send the report without any human interaction.So I want to disable this security notification. I searched on Google and here is the code I have so far but giving me errors and I am not sure what else I should do. Thanks for your help in advance. I am a beginner programmer. The error is
Public Sub Send_Report()
Dim strRecipient As String
Dim strSubject As String
Dim strMessageBody As String
Dim outlookapp As Outlook.Application
Set outlookapp = CreateObject("Outlook.Application")
OlSecurityManager.ConnectTo outlookapp 'error is here says object required
OlSecurityManager.DisableOOMWarnings = True
On Error GoTo Finally
strRecipient = "[email protected]"
strSubject = "Tile of report"
strMessageBody = "Here is the message."
DoCmd.SendObject acSendReport, "Report_Name", acFormatPDF, strRecipient, , , strSubject, strMessageBody, False
Finally:
OlSecurityManager.DisableOOMWarnings = False
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到错误是因为
OlSecurityManager
什么都没有。您还没有声明它,也没有将其设置为任何内容,因此当您尝试使用它时,VBA 不知道您在说什么!您似乎正在尝试使用 Outlook 安全管理器,这是一个出售的加载项
如果您确实拥有它,那么您可能需要像这样声明和设置它:
如果您(我怀疑)没有它,那么另一种选择是使用 CDO 发送电子邮件。下面是一个例子:
首先,在“工具”>“工具”中设置对 CDO 库的引用。参考文献>> Microsoft CDO for Windows Library 旁边的复选标记或类似内容。
这比 Outlook 有点烦人,因为您需要提前知道要使用的 SMTP 服务器的地址。
You get the error because
OlSecurityManager
is nothing. You haven't declared it, you haven't set it to anything, so when you attempt to use it, VBA has no idea what you're talking about!It looks like you're trying to use Outlook Security Manager, which is an add-in sold here. Have you purchased it? Because if not, then you probably don't have it on your system.
If you do have it, then you probably need to declare and set it like this:
If you, as I suspect, don't have it, then an alternative is sending e-mail using CDO. Here's an example:
First, set a reference to the CDO library in Tools > References > checkmark next to Microsoft CDO for Windows Library or something like that.
This is a bit more annoying than Outlook, because you need to know in advance the address of the SMTP server to be used.
我知道这是一个迟到的答案,但我刚刚遇到了类似的问题。还有另一个使用
Outlook.Application
的解决方案!我在寻找解决方案时偶然发现了它,这里完全归功于:
http://www.tek-tips.com/faqs.cfm?fid=第 4334
章 以下:
I know this is a late answer, but I just ran into a similar problem. There is another solution using
Outlook.Application
!I stumble upon it while looking for the solution, full credit here:
http://www.tek-tips.com/faqs.cfm?fid=4334
But what this site's solution simply suggest, instead of using the
.send
command, use the `.Display" command and then send some keys from the keyboard to send the email, like below: