使用ActiveExplorer从Outlook Mailitem获取所选文本(不是ActiveInspector)

时间:2015-01-26 13:47:05

标签: vba outlook

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

我见过的所有代码都使用ActiveInspector,但在我的情况下我需要使用ActiveExplorer(也就是预览窗格,如果我弄错了请纠正我)

我尝试过使用以下内容,但没有成功

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

3 个答案:

答案 0 :(得分:2)

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

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

或者您可以使用Redemption,它通过SafeExplorer对象(也展示功能区和其他一些好东西)显式地公开预览窗格:

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

答案 1 :(得分:0)

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

'
' 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

答案 2 :(得分:-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

显然,您需要先创建一个资源管理器实例,然后再要求它返回最顶层的项目。

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