我有現有的代碼從一個表在我的Excel文件發送郵件 -發送從Excel工作表中多個附件用VBA
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 2015-03-25 09:50:08
循環遍歷文件路徑的範圍並依次添加每個文件路徑。 – Rory 2015-03-25 09:59:10
您可以多次使用'.Attachments.Add'來添加每個附件。每次將其引用到可能使用循環的不同路徑。 – izzymo 2015-03-25 10:09:50