我有一个工作宏,可以向数百名员工发送通信。
我在Excel中使用HTML个性化内容。单元格包含消息。
现在,我需要发送带有多个附件的电子邮件。
这是不带附件的代码。
Sub SendMail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
For i = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.SentOnBehalfOfName = "HC-Communications@company.com"
.To = Cells(i, 1).Value
.CC = Cells(i, 2).Value
.BCC = Cells(i, 3).Value
.Subject = Cells(i, 4).Value
.BodyFormat = olFormatHTML
.HTMLBody = Cells(i, 5).Value
.Display
.ReadReceiptRequested = True
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
Next
End Sub
答案 0 :(得分:0)
似乎您对Attachments
类的Add方法感兴趣,该方法在Attachments
集合中创建了一个新附件。附件的来源可以是文件(由具有文件名的完整文件系统路径表示)或构成附件的Outlook项目。例如:
Sub AddAttachment()
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = Application.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Test.doc", olByValue, 1, "Test"
myItem.Display
End Sub