我正在尝试使用代码发送带有附件的电子邮件。发送一封电子邮件时可以使用,但我需要使用相同的代码发送一批电子邮件,但收件人和附件的批次不同。我仍在学习VBA,因此将不胜感激。
尝试了包括错误在内的一些修复程序,但未能解决问题。
Sub Send_Emails()
Dim OutApp As Object: Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object: Set OutMail = OutApp.CreateItem(0)
'Send Email
With OutMail
.SentOnBehalfOfName = "My-Communications@mymail.com"
.To = "jay.shaun@yahoo.com"
.Subject = "Subject"
.Body = "Date: 18-Jul-2019"
.Attachments.Add "C:\Users\100000\Desktop\RSU A-W\Smith, John_ID 100000- RSU Agr 1 July 2019.pdf"
.Display
.Send
'Send Email
With OutMail
.SentOnBehalfOfName = "My-Communications@mymail.com"
.To = "rich.smith@yahoo.com"
.Subject = "Subject"
.Body = "Date: 18-Jul-2019"
.Attachments.Add "C:\Users\100000\Desktop\image.jpg"
.Display
.Send
End With
On Error Resume Next:
OutMail = Nothing
OutApp = Nothing
End Sub
出现了一个编译错误“ Expected End With”。