附上要通过电子邮件发送的文件EXCEL

时间:2017-07-31 16:03:59

标签: excel excel-vba vba

我需要向不同的客户发送包含少量附件的电子邮件。附件放在不同的文件夹中,每个文件夹都以名称命名。

例如......

In column "A" = Clients name
In column "B" = Clientes emails
In column "C" = The subject
In column "D" = The email body (ex: Hello, here the attachemtn)
In column "E" = The folder where the attachemtns are on

我需要为每个客户提供一个例程(+ - 14个客户)。 注意到在这方面取得了任何成功。 有什么帮助吗?

Sub SendEMAIL()

Dim MyOlapp As Object, MeuItem As Object
Set MyOlapp = CreateObject("Outlook.Application")
Set MeuItem = MyOlapp.CreateItem(olMailItem)
With MeuItem
.to = Range("A2")
.Subject = Range("D2")
.Body = "Range("C2")

End With
End Sub

1 个答案:

答案 0 :(得分:1)

这是我用于Outlook发送带附件的电子邮件的脚本...

Sub NLANghtRpt()
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

 'location of your files
myPath1 = "C:\Users\username\Documents\"


Set myItem = Application.CreateItem(olMailItem)
With myItem
    .To = "whoever you want to send to"  
    .CC = "whoever you want to copy"
    .Subject = "your subject here"
    .Body = "NIGHTLY REPORT FOR  " & Format(Now, "mm.dd.yy")
      ' I use the previous line for a generic message with a time stamp

 Set myAttachments = myItem.Attachments

myAttachments.Add myPath1 & ("ReportSchedule.xls")
myAttachments.Add myPath1 & ("ReportBooks.xls")
myAttachments.Add myPath1 & ("ReportHours.xls")


 myItem.Display
 End With
End Sub

当然,编辑以适应您的环境。祝你好运

相关问题