即使邮件成功发送后,Outlook邮件发送也会触发错误

时间:2018-02-08 06:29:21

标签: vba outlook outlook-vba

我正在尝试将Outlook集成到VBA中。所以我按下按钮点击了一个示例代码,如下所示。

Private Sub CommandButton1_Click()
On Error GoTo ErrHandler
    Dim objOL As New Outlook.Application
    Dim objML As Outlook.MailItem
    Set objML = objOL.CreateItem(olMailItem)
    With objML
        .to = "email@email.com"
        .Subject = "This is a test message from Sandeep Thomas via VBA"
        .Body = "Hi there"
        .Send
    End With
    Set objOL = Nothing: objML = Nothing
Done:
    Exit Sub

ErrHandler:
    MsgBox "Error " + Err.Description
End Sub

但即使在邮件到达收件箱后,我仍然收到此消息“项目已被移动或删除”。我没有得到我做错了。

1 个答案:

答案 0 :(得分:2)

试试这个:

Set objOL = Nothing: Set objML = Nothing