Consulting

Results 1 to 6 of 6

Thread: Getting selected text in Outlook???

  1. #1
    VBAX Regular
    Joined
    Nov 2008
    Posts
    7
    Location

    Question Getting selected text in Outlook???

    I've read tons of postings and I can't find anything that works for what I want to do. I want users to be able to select text in an email subject or body (preferably in both the preview pane or open email), and then either click a button, right click, or use a hotkey to run a macro I've written that uses that text.

    I've not been able to successfully get the selected text in Outlook.

  2. #2
    This function will return the selected text of an open inspector window, i.e. if you open an email in its own window and have it as the active window, this should pick it up...I can't get it to work on the main Outlook window, which I believe is an explorer, though it should work about the same, except instead of ActiveInspector.HTMLEditor it should be ActiveExplorer.HTMLDocument, but like I said that doesn't seem to work...

    [VBA]Function GetSelectedTextOnActiveWindow() As String
    On Error Resume Next
    Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"

    Case "Inspector"
    GetSelectedTextOnActiveWindow = ActiveInspector.HTMLEditor.Selection.createRange.Text
    Case Else
    End Select
    On Error GoTo 0
    End Function[/VBA]

  3. #3
    VBAX Regular
    Joined
    Nov 2008
    Posts
    7
    Location
    I still couldn't get it to work. It just returned "". I think that may be because to run the code it takes focus off the selected text???? For some weird reason, and only once out of a dozen tries, it returned the message subject.

  4. #4
    That's strange, I don't have that problem running it...I'm using Outlook 2003, and like I said it only works when the email message is open in its own window, not when it's open in the preview pane...

  5. #5
    VBAX Regular
    Joined
    Nov 2008
    Posts
    7
    Location
    I figured out my problem. It does work as long as the email is in HTML format, but if it is Rich text or plain text it doesn't work. I made a "Select Case" that will use different lines to get the selected text depending on the email editor type, but haven't been able to get the other two (non-HTML) to work yet. BUT, much closer!!!!!

  6. #6
    VBAX Regular
    Joined
    Nov 2008
    Posts
    7
    Location
    I'm getting frustrated now. It shouldn't be this hard!!!

    I've tried numerous ways and just can't get this to work for WordEditor like it does for HTMLEditor.

    Come on smart folks, help a guy out.....
    Last edited by mavol; 11-13-2008 at 09:37 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •