【发布时间】:2021-07-02 07:21:50
【问题描述】:
我有一个包含以下 5 列的 Excel 电子表格:
- 发票号码、2) 公司、3) 主要电子邮件地址、4) 次要电子邮件地址、5) 帐号
我还有一个包含发票的文件夹。每张发票的文件名中都有发票编号——即 Inv_123456.pdf
我想构建一个 Excel 宏,当我提供发票编号列表时,它将:
- 打开一封电子邮件——收件人:
- 在主题中填写发票编号,然后
- 转到包含发票的文件夹并附上名为 InvNo_*.pdf 的相应发票,即 InvNo_123456.pdf
对每个发票编号重复此操作,并显示电子邮件以供查看。 *最初,我想显示带有附件的电子邮件,直到我对宏按预期工作感到满意为止。
包含预填发票的文件夹的路径是 -- C:\Users\christma-2\OneDrive - OurYear2Win\Documents\Clorodet\Invoice Emails\Attachments\Invoice_*.pdf
以下是我目前创建的宏。我想提取具有相应发票编号的发票并将其附加到电子邮件中。
Sub Send_Email_to_List()
Dim OL As Object, MailSendItem As Object
Dim MsgTxt As String
Set OL = CreateObject("Outlook.Application")
For Each xCell In ActiveSheet.Range(Range("C1"), Range("C" & Rows.Count).End(xlUp))
user_email = xCell.Value
user_subject = "Subject Line for the Email"
user_msg = "Thank You For Submitting this email"
Set MailSendItem = OL.CreateItem(olMailItem)
With MailSendItem
.Subject = user_subject
.Body = user_msg
.To = user_email
.CC = " "
.Bcc = "clorodet20607@aol.com"
'I need help getting the correct attachment, putting the invoice number in the subject, and cc'ing the secondary contacts
.Attachments.Add ("C:\Users\christma-2\OneDrive - OurYear2Win\Documents\Clorodet\Invoice Emails\Attachments\W1\???.pdf")
.Display
End With
Next xCell
Set OL = Nothing
End Sub
【问题讨论】:
标签: email attachment