首页 > 解决方案 > 在 excel vba、OLE 问题上发送大量电子邮件

问题描述

我希望你做得很好。

我正在使用此代码在 VBA Excel 中发送电子邮件,但它只能工作一次,然后我必须在任务管理器上关闭 Outlook。如果我不这样做,我会收到一条消息“Microsoft Excel 正在等待另一个应用程序完成 OLE 操作”。我唯一需要做的就是关闭任务管理器上的 Outlook 应用程序,然后它就可以正常工作了。

你能帮我解决这个问题吗?下面我将发布我的代码

Dim email As Outlook.MailItem
Dim direc As String
Dim body As String
Set A = New Outlook.Application

For i = 2 To ActiveSheet.Cells(Rows.Count, 16).End(xlUp).Row
direc = Worksheets("NewSheet").Cells(i, 16).Value

Set email = A.CreateItem(emailItem)
    With email
    direc = Worksheets("NewSheet").Cells(i, 16).Value
        If (direc <> "0") Then
            .To = direc
            .Subject = "Notification Test"
            body = Worksheets("NewSheet").Cells(i, 14)
            .HTMLBody = "<HTML><BODY style=font-size:11pt;font-family:Calibri>This is a notification reminder to let you know that you have <b>" & body & "</b> open contact(s) that you must Update</BODY><br><br>Best Regards, </br></br><br> Anonymous </br></HTML>"
            .Display
            .Send
        End If
    End With
Next i

非常感谢您的时间和帮助。

标签: excelvbaoutlookcom-automation

解决方案


不要同时调用DisplaySend。摆脱显示线。


推荐阅读