从excel中读取多行,然后将它们添加到电子邮件中的.htmlbody

时间:2019-07-12 19:35:15

标签: html excel vba html-email

我正在尝试整理一些代码,自从我使用VBA以来已经有很长时间了,所以我感觉很好,而且真的很生锈。

我有一个Excel电子表格,其中有一些静态单元格,然后再向下是几行数据。每次的行数都会不同。

我希望能够阅读每一行并创建一些格式化的html,然后将其添加到.html正文中,以便我可以直接通过电子邮件发送信息。

我编写的代码将读取信息,但会为我想要的行创建单独的电子邮件,但我希望所有电子邮件中的每一行都包含该信息。

Sub CreateEmail()
Dim CustRow, CustCol, LastRow As Long
Dim Email, EssexInc, EssexCrash, CrashLoc As String
Dim CrashDate, CrashTime As Date
Dim OutApp, OutMail As Object

With Sheet1


EssexInc = .Range("B5").Value 'Set reference Number
EssexCrash = .Range("E5").Value 'Set URN
CrashLoc = .Range("F8").Value 'Set Location
CrashDate = .Range("B8").Value 'Set Date
CrashTime = .Range("D8").Value 'Set Time




LastRow = .Range("E9999").End(xlUp).Row  'Determine Last Row in Table
    For CustRow = 15 To LastRow



        Set OutApp = CreateObject("Outlook.Application") 'Create Outlook Application
        Set OutMail = OutApp.CreateItem(0) 'Create Email


        Email = **'both static and data from the rows'**



        With OutMail
            .To = Sheet1.Range("D" & CustRow).Value
            .Subject = "Crash URN " & EssexCrash
            .HTMLbody = Email
            .Display 'To send without Displaying change .Display to .Send
        End With

Next CustRow

End With
End Sub

我希望每封电子邮件都包含所有静态信息以及所有行数据。

0 个答案:

没有答案