在Outmail.body中返回一个string数组

我正在使用已知的子程序发送一个警告电子邮件outlook每当一个条件得到满足。

在例程中,我定义了名为DatePassed的string数组,其中存储了一些dynamic值,并且我打算在邮件主题中返回它的内容。

问题是,我不知道如何处理DatePassed,以便返回整个数组而不仅仅是第一个元素。

我将如何做到这一点?

Sub Mail_workbook_Outlook_1() Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next Dim DatePassed(100) As Variant Dim i As Integer For i = 6 To 13 If Cells(i, 1) < Date Then DatePassed(i - 6) = Cells(i, 2) End If Next i With OutMail .To = "Joerge@Johnson.com" .CC = "James@Johnson.com" .BCC = "" .Subject = "Unmanaged Clients" .Body = DataPassed .Attachments.Add ActiveWorkbook.FullName .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub 

尝试这个。

我刚刚添加一个Loop来运行Array并将其存储为一个string,然后将其分配给.Body

  Sub Mail_workbook_Outlook_1() Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next Dim DatePassed(100) As Variant Dim i As Integer For i = 6 To 13 If Cells(i, 1) < Date Then DatePassed(i - 6) = Cells(i, 2) End If Next i '================================================= 'New Section Dim DataPassedElementReference As Long Dim DataPassedString As String DataPassedString = "" 'Using 100 as this is waht you used to define the array For DataPassedElementReference = 1 To 100 DataPassedString = DataPassedString & DataPassed(DataPassedElementReference) & " " Next DataPassedElementReference '================================================= With OutMail .To = "Joerge@Johnson.com" .CC = "James@Johnson.com" .BCC = "" .Subject = "Unmanaged Clients" 'Note the difference here '.Body = DataPassed .Body = DataPassedString .Attachments.Add ActiveWorkbook.FullName .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub