需要使用outlook在邮件正文中创建多行

时间:2018-05-10 00:48:27

标签: vba excel-vba outlook-vba excel

我需要在邮件正文中创建2个或更多单独的行,并在下面的代码中将邮件正文之前添加一个Hi的名称...我正在尝试将批量邮件发送到customer.Need帮助最早解决这个问题。

Sub Send_email_fromexcel()
Dim edress As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim attachment As String
Dim x As Integer

 x = 2

Do While Sheet1.Cells(x, 1) <> ""
   
    Set outlookapp = CreateObject("Outlook.Application")
    Set outlookmailitem = outlookapp.createitem(0)
    Set myAttachments = outlookmailitem.Attachments
    path = ""
    edress = Sheet1.Cells(x, 1)
      
    subj = Sheet1.Cells(x, 2)
    filename = Sheet1.Cells(x, 3)
    attachment = path + filename


    
        outlookmailitem.To = edress
        outlookmailitem.cc = ""
        outlookmailitem.bcc = ""
        outlookmailitem.Subject = subj
        
        **' Need Help here  '
        outlookmailitem.body = "Please find your statement attached,& vbcrLf & Kindly check the list and confirm"**
        
           
            
        myAttachments.Add (attachment)
        outlookmailitem.display
        'outlookmailitem.send
            
        lastrow = lastrow + 1
        edress = ""
    x = x + 1

Loop


Set outlookapp = Nothing
Set outlookmailitem = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

您的专线需要插入以“&amp;”分隔的名称连接。

看起来你有正确的想法,但需要保持“&amp;”在双引号之外。

假设custname是持有客户名称的变量,该行应如下所示:

outlookmailitem.body = "Please find your statement attached," & custname & vbcrLf  & "Kindly check the list and confirm"