【发布时间】:2020-09-22 15:13:06
【问题描述】:
通过 Outlook 发送时遇到间歇性 Excel VBA 问题。
我的客户每天发送 20 或 30 次电子邮件文件。大约每周一次,电子邮件不发送。它不在发件箱或已发送。我们只有在收到没有相应电子邮件的实物样品时才会知道,通常是第二天。
相关的Excel VBA代码:
'[bunch of code that sets everything up in order to send]
Err.Clear
On Error Resume Next
Set OutMail = oOutlook.CreateItem(0) ' [oOutlook is a previously created object which is an instance of Outlook]
With OutMail
.To = Address ' [Address=email I have pre-filled]
.Subject = "Swabs File"
.body = vbAns ' [vbAns = variant I have pre-filled]
.Attachments.Add (Dir) ' [Dir = string which is the name of the file]
.send
End With
'Error trap if there is any problem at all
If Err Then
MsgBox ("Problem with Outlook - Failed to Send. Please try again")
Exit Sub
else
MsgBox ("Your file has been sent")
End If
当问题发生时,错误没有被捕获,客户端认为他们已经成功发送了文件。
如何捕获错误?
【问题讨论】: