将Excel数据表条目拉入Outlook电子邮件模板的收件人中

时间:2018-06-20 17:03:00

标签: excel vba excel-vba outlook outlook-vba

目标是将Excel数据表/数据透视表连接到Outlook电子邮件模板。

是否可以将原始条目创建者从数据透视表或表字段中拉出到收件人部分中以发送电子邮件?我正在尝试自动从该数据表向多个用户发送电子邮件。表中提供了有关向谁发送电子邮件的信息。

这是我到目前为止所拥有的:

Sub SendMail()
    Dim olApp As Outlook.Application 
    Dim olMail As Outlook.MailItem 
    Dim  blRunning As Boolean

    blRunning = True 
    on Error Resume Next 
    Set olApp = GetObject (,"Outlook.Application") 
    If olApp Is Nothing Then 
        Set olApp = New Outlook.Application 
        blRunning = False 
    End If  
    On Error GoTo 0 

    Set olMail = olApp.CreateItem(olMailItem) 
    With olMail 
        .Subject = "Automatic Entry Support" 
        .Recipients.Add "J.Doe@gmail.com"  
        .Attachments.Add "C:\Users\J.Doe\Documents\Project\Template draft.xlsx"  
        .Body = "Support message" 
        .Display ("Spell check, data attached?, SEND")
    End With
    If Not blRunning Then olApp.Quit

    Set olApp = Nothing
    Set olMail = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

查找表的最后一行,并循环浏览收件人。检查一下:

https://www.rondebruin.nl/win/s1/outlook/mail.htm