none
How do you capture selected text in outlook via a context menu?

    Question

  • I have an office 2010 plugin and i would like to specify a custom context menu that uses the currently selected text. Can anyone tell me how to get the currently selected text in a callback for my ribbon? (it's an XML ribbon, not a drag & drop UI ribbon) Cheers Kev
    http://esendexdeveloper.blogspot.com/
    Tuesday, December 06, 2011 8:54 AM

Answers

  • No.
     
    Inspectors are the windows used to display open items. If nothing is opened there are no Inspectors. Explorers are the windows used to display folders, and there isn't a way to get any selected text in the preview/reading pane of an Explorer window.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:0fe34fa2-9e7e-495b-9e60-752ec5ad96ad...

    Hi Ken,

    thanks for the reply. I will test that later but i'm in the middle fo debugging another issue right now.

    What if the number is in the preview pane, will ActiveInspector() still get me the details?

    Cheers

     

    Kev


    Ken Slovak MVP - Outlook
    • Marked as answer by Kev Pearman Thursday, January 12, 2012 10:34 AM
    Wednesday, December 07, 2011 3:16 PM
    Moderator
  • Use Inspector.WordEditor.Application.Selection.Text.

    You might want to check first that Selection.Type is not 1 (wdSelectionIP) or 0 (wdNoSelection).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Marked as answer by Kev Pearman Thursday, January 12, 2012 10:33 AM
    Tuesday, January 10, 2012 4:55 PM

All replies

  • For an open item you would use the ActiveInspector() object and get Inspector.WordEditor. All 2010 emails use WordMail. The WordEditor object is a Word.Document object, so you can cast WordEditor to Word.Document. From there you would use the Word object model to get the Document.ActiveWindow.Selection..

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:a7347989-926a-426c-ae6f-e51f73a2de64...
    I have an office 2010 plugin and i would like to specify a custom context menu that uses the currently selected text. Can anyone tell me how to get the currently selected text in a callback for my ribbon? (it's an XML ribbon, not a drag & drop UI ribbon) Cheers Kev
    http://esendexdeveloper.blogspot.com/

    Ken Slovak MVP - Outlook
    • Marked as answer by Kev Pearman Wednesday, December 14, 2011 4:56 PM
    • Unmarked as answer by Kev Pearman Tuesday, January 03, 2012 10:15 AM
    Tuesday, December 06, 2011 2:06 PM
    Moderator
  • Hi Ken,

    thanks for the reply. I will test that later but i'm in the middle fo debugging another issue right now.

    What if the number is in the preview pane, will ActiveInspector() still get me the details?

    Cheers

     

    Kev

    Wednesday, December 07, 2011 10:06 AM
  • No.
     
    Inspectors are the windows used to display open items. If nothing is opened there are no Inspectors. Explorers are the windows used to display folders, and there isn't a way to get any selected text in the preview/reading pane of an Explorer window.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:0fe34fa2-9e7e-495b-9e60-752ec5ad96ad...

    Hi Ken,

    thanks for the reply. I will test that later but i'm in the middle fo debugging another issue right now.

    What if the number is in the preview pane, will ActiveInspector() still get me the details?

    Cheers

     

    Kev


    Ken Slovak MVP - Outlook
    • Marked as answer by Kev Pearman Thursday, January 12, 2012 10:34 AM
    Wednesday, December 07, 2011 3:16 PM
    Moderator
  • I've tried your solution, it's took a while as other things took priority, and i get an exception.

    Here's my code

    Word.Document email = (Word.Document)Inspector.WordEditor;
    Window window = email.ActiveWindow;
    

    And the COM Exception occurs on the ActiveWindow property

    Error Code -2146822130

    This object model command is not available in e-mail.

     

    Cheers

     

     

    Kev


    http://endgameinteractive.co.uk
    • Edited by Kev Pearman Tuesday, January 03, 2012 10:24 AM
    Tuesday, January 03, 2012 10:18 AM
  • Where are you running this code, and in what event handler?
     
    Is this with an open item (Inspector), and are you getting a valid Inspector object?
     
    Is this in an active mail window? If the Activate() event hasn't fired in the Inspector yet you won't get a valid WordEditor object and the window won't be activated yet.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:f41dfe10-6435-4219-bab1-dede5008e671...

    I've tried your solution, it's took a while as other things took priority, and i get an exception.

    Here's my code

    Word.Document email = (Word.Document)Inspector.WordEditor;
    Window window = email.ActiveWindow;
    

    And the COM Exception occurs on the ActiveWindow property

    Error Code -2146822130

    This object model command is not available in e-mail.

     

    Cheers

     

     

    Kev


    http://endgameinteractive.co.uk

    Ken Slovak MVP - Outlook
    Tuesday, January 10, 2012 4:11 PM
    Moderator
  • Next version of Redemption will introduce a new object - SafeExplorer, which provides (besides other things) access to the Reading Pane.

    Let me know if you are interested in a beta version.

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

     

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Tuesday, January 10, 2012 4:53 PM
  • Use Inspector.WordEditor.Application.Selection.Text.

    You might want to check first that Selection.Type is not 1 (wdSelectionIP) or 0 (wdNoSelection).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Marked as answer by Kev Pearman Thursday, January 12, 2012 10:33 AM
    Tuesday, January 10, 2012 4:55 PM
  • Ken,

    I was running the code from a gettext ribbon callback on a context menu, i wanted to display the selected text in the context menu.This was from an open email as per our previous discussion, rather than the preview pane. If you have an answer i'd be interested to hear it and it may benefit other users but we have decided to go down a different route.

    We now parse all text in an email, which we can also do in the preview pane, and pull out any text matching a regular expression rather than requireing the user to highlight text first. This has actually proved to be a better solution than the one we were originally considering as our plugin enables users to make phone calls through outlook and this way you can call any phone number that matches the regular expression in our "Make Call" window.

     

    Cheers

     

    Kev


    http://endgameinteractive.co.uk
    Wednesday, January 11, 2012 9:35 AM
  • Thanks for the offer Dmitry but we seem to have solved our current issues as per my previous post.

    Cheers

     

    Kev


    http://endgameinteractive.co.uk
    Wednesday, January 11, 2012 9:36 AM
  • I'd try what Dmitry mentioned about using Application.ActiveWindow rather than Document.ActiveWindow and seeing if that works in the context of the WordEditor dll as opposed to the full Word.
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:0b44aa3f-bf83-4d72-96df-193ec29756fc...

    Ken,

    I was running the code from a gettext ribbon callback on a context menu, i wanted to display the selected text in the context menu.This was from an open email as per our previous discussion, rather than the preview pane. If you have an answer i'd be interested to hear it and it may benefit other users but we have decided to go down a different route.

    We now parse all text in an email, which we can also do in the preview pane, and pull out any text matching a regular expression rather than requireing the user to highlight text first. This has actually proved to be a better solution than the one we were originally considering as our plugin enables users to make phone calls through outlook and this way you can call any phone number that matches the regular expression in our "Make Call" window.

     

    Cheers

     

    Kev


    http://endgameinteractive.co.uk

    Ken Slovak MVP - Outlook
    Wednesday, January 11, 2012 3:21 PM
    Moderator