我有一个元素数量未知的数组。所有到Outlook的数组元素mailitem
我想了解如何将所有数组元素插入到我要发送的电子邮件正文中。
有没有一种方法可以引用数组的所有项目(不知道有多少元素存在)?
我的代码是下面
Dim MyArray() As String
Dim Msg As Object
Dim item As Object
Set olApp = GetObject(, "Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
olItms.Sort "Received", False 'False = Ascending = Older to newer
i = 0
For Each Msg In olItms
If Msg.Class = olMail Then
If InStr(1, Msg.Subject, "1401001LS") > 0 Then
ReDim Preserve MyArray(i)
If i = 0 Then
MyArray(i) = "From: " & Msg.Sender & vbNewLine & "Sent: " & Msg.SentOn & vbNewLine & "To: " & Msg.To & vbNewLine & "CC: " & Msg.CC & vbNewLine & "Subject: " & Msg.Subject & vbNewLine & vbNewLine & Msg.Body
End If
If i > 0 Then
MyArray(i) = "From: " & Msg.Sender & vbNewLine & "Sent: " & Msg.SentOn & vbNewLine & "To: " & Msg.To & vbNewLine & "CC: " & Msg.CC & vbNewLine & "Subject: " & Msg.Subject & vbNewLine & vbNewLine & Split(Msg.Body, "From: ")(0)
End If
i = i + 1
End If
End If
Next Msg
Unload Me
Done.Show
End Sub
可以通过使用UBOUND(MYARRAY) – Sorceri
我找到一个数组的长度我意识到这一点,但我仍然无法找出将所有数组插入一个Msgbody的方法。 – AndroidDev