我有一个自动发送或显示电子邮件的代码。
Set OutApp = CreateObject("Outlook.Application")
Set outmail = OutApp.CreateItem(olMailItem)
With outmail
.To = c.Value
.BCC = "xxxxx@yyyyyy.com"
.Subject = Range("B1")
.HTMLBody = RangetoHTML(s)
On Error Resume Next
.Attachments.Add (DFile1)
.Attachments.Add (DFile2)
.Attachments.Add (DFile3)
.Attachments.Add (DFile4)
.Attachments.Add (DFile5)
'.Send 'to send directly
.Display 'to display email
End With
当我使用.Send
时效果很好,但是当我使用.Display
时,宏运行正常但没有显示任何内容
答案 0 :(得分:2)
我认为你要做的是检查每个附件,然后跳过使用On Error Resume Next
,这样你就可以做到我不喜欢的了..
On Error Resume Next
.Attachments.Add (DFile1)
On Error Resume Next
.Attachments.Add (DFile2)
On Error Resume Next
.Attachments.Add (DFile3)
On Error Resume Next
.Attachments.Add (DFile4)
On Error Resume Next
.Attachments.Add (DFile5)
On Error GoTo 0
但我会做的是这样的事情
'// Attachment Path
AtmtsPath = "C:\Temp\"
'// Add attachments to the message.
Atmts = Dir(AtmtsPath & "*.*")
Do While Len(Atmts) > 0
.Attachments.Add AtmtsPath & Atmts
Atmts = Dir
Loop