发送多个邮件的代码:
Sub main() For i = 1 To 3 Call SendMail Next i End Sub
Sub SendMail() Dim objOL As Object Dim itmNewMail As Object
Set objOL = CreateObject("Outlook.Application") Set itmNewMail = objOL.CreateItem(olMailItem)
f = "C:\temp\test.txt" With itmNewMail .Subject = "Reminder" .Body = " Please see the attachment" .To = "your.email@address.com" .Attachments.Add f End With On Error GoTo continue SendEmail: itmNewMail.display DoEvents DoEvents DoEvents SendKeys "%s", Wait:=True DoEvents itmNewMail.display GoTo SendEmail continue: On Error GoTo 0 Set objOL = Nothing Set itmNewMail = Nothing End Sub 原代码是利用错误陷阱达到发送邮件的目的,但错误陷阱在一个过程中不能反复使用,需将一个过程拆分为两个过程。 |