【发布时间】:2011-07-04 17:30:44
【问题描述】:
我正在尝试在宏中使用 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 = "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
【问题讨论】: