首页 > 解决方案 > 我收到运行时错误“429”。试图让 Excel 宏发送电子邮件

问题描述

Sub SendEmail()
'    SendEmail Macro
'
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)

    olMail.To = ""
    olMail.CC = ""
    olMail.Subject = " There is a change to the EMR adjustment Form that Approval"
    olMail.Send
End Sub

标签: vbaoutlook

解决方案


你混淆了早期和晚期绑定,

后期绑定使用 Visual BasicGetObject函数或CreateObject初始化 Outlook 的函数

例子

Dim olApp as Object 
Set olApp = CreateObject("Outlook.Application")

要使用早期绑定,首先需要设置对 Outlook 对象库的引用,Microsoft Outlook xx.x 对象库

例子

Dim olApp as Outlook.Application 
Set olApp = New Outlook.Application

推荐阅读