PDA

View Full Version : Getting selected text in Outlook???



mavol
11-11-2008, 03:25 PM
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.:banghead:

jfournier
11-12-2008, 07:00 AM
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...

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

mavol
11-12-2008, 07:58 AM
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.

jfournier
11-12-2008, 08:04 AM
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...

mavol
11-12-2008, 12:48 PM
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!!!!!

mavol
11-12-2008, 01:47 PM
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.....