使用VBA禁用Outlook安全设置 [英] Disable outlook security settings using VBA

查看:579
本文介绍了使用VBA禁用Outlook安全设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动电子邮件,接入宏使用VBA的报告。该报告是由ACCESS2007通过outlook2007发送。当正在发送的报告中,我从Outlook中的安全消息说:一个程序正试图访问您的通讯簿或联系人或程序试图访问已存储在Outlook中的电子邮件地址...。因为我想使用Windows任务计划自动发送该报告没有任何人为interaction.So我想禁用此安全通报这个消息是一个问题对我来说。我搜索谷歌和这里是code我有这么远,但给我的错误,我不知道还有什么我应该做的。感谢您的帮助提前。我是一个初学编程的。该错误是

 公用Sub Send_Report()
昏暗strRecipient作为字符串
昏暗strSubject作为字符串
昏暗strMessageBody作为字符串
昏暗outlookapp作为Outlook.Application

设置outlookapp =的CreateObject(Outlook.Application)

OlSecurityManager.ConnectTo outlookapp'的错误是在这里说,所需的对象

OlSecurityManager.DisableOOMWarnings = TRUE
对错误转到最后

strRecipient =example@yahoo.com
strSubject =报告瓷砖
strMessageBody =这里的消息。

DoCmd.SendObject acSendReport,REPORT_NAME,acFormatPDF,strRecipient,,,strSubject,strMessageBody,假

最后:
OlSecurityManager.DisableOOMWarnings =假


结束小组
 

解决方案

您得到的错误,因为 OlSecurityManager 是什么。你还没有宣布它,你有没有设置任何东西,所以当你尝试使用它,VBA根本不知道你在说什么!

它看起来像您尝试使用Outlook安全管理,这是一个附加在出售的此处。你购买了它?因为如果没有,那么你可能没有在系统上。

如果你有,那么你可能需要声明,并将其设置是这样的:

 昏暗OlSecurityManager作为AddinEx press.Outlook.SecurityManager
设置OlSecurityManager =新AddinEx press.Outlook.SecurityManager
 

如果你,我怀疑,没有它,那么另一种方法是使用CDO发送电子邮件。这里有一个例子:

首先,设置一个参考CDO库工具>参考>勾选旁边的微软CDO的Windows库的或类似的东西。

 暗淡cdoConfig
昏暗的msgOne

设置cdoConfig =的CreateObject(CDO.Configuration)
随着cdoConfig.Fields
    .Item(cdoSendUsingMethod)= cdoSendUsingPort
    .Item(cdoSMTPServerPort)= 25'的端口号,一般为25
    .Item(cdoSMTPServer)=yourSMTPserver.com
    .Item(cdoSendUserName)=您的用户名如果​​需要的话
    .Item(cdoSendPassword)=您的密码,如果需要的话
    .Update
结束与

设置msgOne =的CreateObject(CDO.Message)
随着msgOne
    设置.Configuration = cdoConfig
    。为了=recipient@somehwere.com
    。从=you@here.com
    .subject =测试CDO
    .TextBody =它工作得很好。
    .Attachments.AddC:\ myfile.pdf
    。发送
结束与
 

这是更讨厌比展望了一下,因为你需要预先知道SMTP服务器的地址中使用。

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 = "example@yahoo.com"
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

解决方案

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:

Dim OlSecurityManager As AddinExpress.Outlook.SecurityManager
Set OlSecurityManager = New AddinExpress.Outlook.SecurityManager

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.

Dim cdoConfig
Dim msgOne

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServerPort) = 25 'your port number, usually is 25
    .Item(cdoSMTPServer) = "yourSMTPserver.com" 
    '.Item(cdoSendUserName) = "your username if required"
    '.Item(cdoSendPassword) = "your password if required"
    .Update
End With

Set msgOne = CreateObject("CDO.Message")
With msgOne
    Set .Configuration = cdoConfig
    .To = "recipient@somehwere.com"
    .from = "you@here.com"
    .subject = "Testing CDO"
    .TextBody = "It works just fine."
    .Attachments.Add "C:\myfile.pdf"
    .Send
End With

This is a bit more annoying than Outlook, because you need to know in advance the address of the SMTP server to be used.

这篇关于使用VBA禁用Outlook安全设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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