gpt4 book ai didi

excel - 通过 Excel VBA 发送带附件的电子邮件

转载 作者:行者123 更新时间:2023-12-04 12:12:44 27 4
gpt4 key购买 nike

我想通过 Outlook 从 Excel 中通过电子邮件发送报告。

我正在使用我自己和同事的电子邮件地址对此进行测试。我收到“无法送达” Error .

该消息说无法联系到收件人,并建议稍后尝试发送电子邮件。

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

最佳答案

确保引用 Outlook 对象库

Option Explicit
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:\temp\test1.xlsx"
OlMail.Display ' <--for testing, to send use OlMail.Send

'OlMail.Send
End Sub
添加多个 CcRecipient In Array("jon.doe@aol.com","jon.doe@aol.com")

关于excel - 通过 Excel VBA 发送带附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30630767/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com