我有这个 VBA 代码用于在我的 Access 数据库中发送电子邮件,并且我还引用了 Microsoft Outlook 14.0 对象库。
当我手动运行代码时,一切正常。但是,当我从 Windows 任务计划运行宏时,访问失败。我收到这条消息:
运行时错误“429”ActiveX 组件无法创建对象
在任务计划程序的“操作”选项卡中,我引用这样的宏:“C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE”“C:\mydata\Database\mydatabase.accdb”/X RunMyMacro
该错误似乎指向此代码,如下面的屏幕截图所示。
代码:
Dim strEmailBody As String
Sub emailNotification()
Dim oFolder As Outlook.MAPIFolder
Dim oItem As Outlook.MailItem
Dim oOutlook As New Outlook.Application
Dim MoOutlook As Outlook.NameSpace
Set MoOutlook = oOutlook.GetNamespace("MAPI")
Set oFolder = MoOutlook.GetDefaultFolder(olFolderOutbox)
Set oItem = oFolder.Items.Add(olMailItem)
With oItem
.Recipients.Add ("tome@me.com")
.Subject = "my notification"
.Body = strEmailBody
.Importance = olImportanceHigh
.Send
End With
Set oFolder = Nothing
End Sub
截屏: