我已经有现有的代码可以从我Excel文件中的一个Sheet发送邮件——
Sub CreateMail()
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Dim rngAttach As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
Application.ScreenUpdating = False
Worksheets("Mail List").Activate
With ActiveSheet
Set rngTo = .Range("B1")
Set rngSubject = .Range("B2")
Set rngBody = .Range("B3")
Set rngAttach = .Range("B4")
End With
With objMail
.To = rngTo.Value
.Subject = rngSubject.Value
.body = rngBody.Value
.Attachments.Add rngAttach.Value
.display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
End Sub
然而,我想要包含一些附件,因此Set rngAttach = .Range("B4")
不能帮助实现这一点。
请问有什么帮助吗? 提前感谢!
B4
中是什么 - 文件路径吗? - brettdj.Attachments.Add
来添加每个附件。每次都可以使用循环将其引用到不同的路径。 - izzymo