我希望能够从Excel中通过Outlook发送报告。
我正在使用自己和同事的电子邮件地址进行测试。我收到了一个“无法投递”的错误
。
该消息显示无法联系到收件人,并建议稍后尝试发送该电子邮件。
Sub CreateEmail()
Dim OlApp As Object
Dim OlMail As Object
Dim ToRecipient As Variant
Dim CcRecipient As Variant
Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.createitem(olmailitem)
For Each ToRecipient In Array("jon.doe@aol.com")
OlMail.Recipients.Add ToRecipient
Next ToRecipient
For Each CcRecipient In Array("jon.doe@aol.com")
With OlMail.Recipients.Add(CcRecipient)
.Type = olCC
End With
Next CcRecipient
'Fill in Subject field
OlMail.Subject = "Open Payable Receivable"
'Add the report as an attachment
OlMail.Attachments.Add ("C:\OpenPayRecPrint2.pdf")
'Send Message
OlMail.Send
End Sub
olCC
的值。如果你让 Outlook 应用程序可见,并注释掉发送行,你可能更容易地找出问题所在。 - Tim Williams.Type = olCC
,您将其更改为.Type = 2 'olCC 的值
。我通常会在行末添加注释,以便提醒自己/他人数字 2 代表什么。 - ChipsLetten