使用 ActiveExplorer(不是 ActiveInspector)从预览窗格中获取选定的文本

Get Selected Text from preview pane using ActiveExplorer (not ActiveInspector)

是否可以使用 ActiveExplorer 获取选定的文本?

我见过的所有代码都使用了 ActiveInspector。我需要使用 ActiveExplorer,也就是预览面板。

我试过了

GMID = Application.ActiveExplorer.Selection.Item(1)

您可以使用以下示例:

Sub GetSelectedItems()
        Dim myOlApp As New Outlook.Application
        Dim myOlExp As Outlook.Explorer
        Dim myOlSel As Outlook.Selection
        Dim MsgTxt As String
        Dim x As Integer
        MsgTxt = "You have selected items from: "
        Set myOlExp = myOlApp.ActiveExplorer
        Set myOlSel = myOlExp.Selection
        For x = 1 To myOlSel.Count
            MsgTxt = MsgTxt & myOlSel.Item(x).SenderName & ";"
        Next x
        MsgBox MsgTxt
    End Sub

显然,您需要先创建一个 explorer 实例,然后才能将其请求到 return 最上面的项目。

Link: https://msdn.microsoft.com/en-us/library/office/aa219397%28v=office.11%29.aspx

以下(使用 Inspector)仍然适用于预览窗格:

set item =  Application.ActiveExplorer.Selection.Item(1)
MsgBox item.GetInspector.WordEditor.Application.Selection.Text

或者您可以使用 Redemption (I am its author), which explicitly exposes the preview pane through the SafeExplorer 对象(它还会显示功能区和其他一些好东西):

set sExplorer = CreateObject("Redemption.SafeExplorer")
sExplorer.Item = Application.ActiveExplorer
MsgBox sExplorer.ReadingPane.SelText

更新 1/1/2021 - 最新版本的 Outlook(2016 和 2019)公开了 Explorer.PreviewPane 属性,可用作

MsgBox Application.ActiveExplorer.PreviewPane.WordEditor.Application.Selection.Text

我有一个应用程序,可以从预览窗格中的最新消息或弹出的消息中检索多个元素。

'
' Check if Outlook is running
If Not Process.GetProcessesByName("OutLook").Length < 1 Then
    Dim app As Outlook.Application = TryCast(GetObject(, "Outlook.Application"), Outlook.Application)
    '
    ' Get last opened/previewed message
    If Not app.ActiveExplorer Is Nothing Then
        Dim message As Outlook.MailItem = TryCast(app.ActiveExplorer.Selection.Item(1), Outlook.MailItem)
        If Not message Is Nothing Then
            '
            ' Sample of exposed elements
            Dim MailTo As String = message.Body
            Dim CopyTo As String = message.CC
            Dim BlindCopyTo As String = message.BCC
            Dim Content As String = message.Body
            Dim SendTime As Date = message.RecievedTime
            Dim SentFrom As String = message.SenderEmailAddress
        End If
    End If
End If