【问题标题】:How to get only one selected mail using VBA (Outlook)如何使用 VBA (Outlook) 仅获取一封选定的邮件
【发布时间】:2019-03-18 14:42:12
【问题描述】:

我有这个代码:

Sub GetSelectedItems()
 Dim myOlExp As Outlook.Explorer
 Dim myOlSel As Outlook.Selection
 Dim mySender As Outlook.AddressEntry
 Dim oMail As Outlook.MailItem
 Dim oAppt As Outlook.AppointmentItem
 Dim oPA As Outlook.PropertyAccessor
 Dim strSenderID As String
 Const PR_SENT_REPRESENTING_ENTRYID As String = _
 "http://schemas.microsoft.com/mapi/proptag/0x00410102"
 Dim MsgTxt As String
 Dim x As Long

 MsgTxt = ""
 Set myOlExp = Application.ActiveExplorer
 Set myOlSel = myOlExp.Selection
 For x = 1 To myOlSel.Count
 If myOlSel.Item(x).Class = OlObjectClass.olMail Then
 ' For mail item, use the SenderName property.
 Set oMail = myOlSel.Item(x)
 MsgTxt = MsgTxt & oMail.Body

 ElseIf myOlSel.Item(x).Class = OlObjectClass.olAppointment Then
 ' For appointment item, use the Organizer property.
 Set oAppt = myOlSel.Item(x)
 MsgTxt = MsgTxt & oAppt.Organizer & ";"
 Else
 ' For other items, use the property accessor to get sender ID,
 ' then get the address entry to display the sender name.
 Set oPA = myOlSel.Item(x).PropertyAccessor
 strSenderID = oPA.GetProperty(PR_SENT_REPRESENTING_ENTRYID)
 Set mySender = Application.Session.GetAddressEntryFromID(strSenderID)
 MsgTxt = MsgTxt & mySender.Name & ";"
 End If
 Next x
 Debug.Print MsgTxt
End Sub

当我运行此代码时,我将获得所选邮件的正文。但是我在当前选定的邮件中收到所有分支的邮件。所以,我只想得到一封选定的邮件,没有分支。

如何做到这一点?

【问题讨论】:

标签: vba outlook


【解决方案1】:

只有一个消息正文。它没有分成在回复/转发交换期间创建的单独部分。解析正文是您的责任。

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 2014-01-18
    • 2022-01-27
    • 2022-10-08
    • 1970-01-01
    相关资源
    最近更新 更多