Get Selected Text from Outlook Mailitem using Acti

2019-08-12 19:03发布

Is it possible to get a selected text using ActiveExplorer ?

All codes I've seen around uses the ActiveInspector, but in my case I need to use ActiveExplorer (aka preview pane, correct me if I am mistaken, please)

I've tried using the following, without success

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

标签: vba outlook
3条回答
ゆ 、 Hurt°
2楼-- · 2019-08-12 19:19

The following (which uses Inspector) still works for the preview pane:

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

Or you can use Redemption, which explicitly exposes the preview pane through the SafeExplorer object (which also exposes the ribbon and a few other goodies):

set sExplorer = CreateObject("Redemption.SafeExplorer")
sExplorer.Item = Application.ActiveExplorer
MsgBox sExplorer.ReadingPane.SelText
查看更多
叼着烟拽天下
3楼-- · 2019-08-12 19:30

I have an application where I retrieve several elements from the most recent message in the preview pane or popped out message.

'
' 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
查看更多
淡お忘
4楼-- · 2019-08-12 19:36

You can use the following example:

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

Apparently, you need to create an instance of explorer before asking it to return the topmost item.

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

查看更多
登录 后发表回答