Copying selected text from a message body

  • Thread starter Thread starter CharlieH
  • Start date Start date
C

CharlieH

Is there a way to (with code) copy user-selected text (within an email body
or other outlook object)?
I've created a form that captures several mailitem objects (SenderName,
SentOn, and Body), but I don't want the entire body. I'd like to give the
user the option of highlighting specific text and, with a command button on
the form, having it copy-pasted into the appropriate textbox on the form.
Thanks.
 
What version of Outlook and what type of emails? For HTML you can get the
HTMLDocument object from the Inspector.HTMLEditor object. For WordMail
emails you can get the selection using the Word object model on the
Inspector.WordEditor object (a Document).

For RTF or plain text messages you cannot get the selection using the
Outlook object model. You'd have to use a 3rd party library such as
Redemption (www.dimastr.com/redemption).
 
Thanks, Ken. Outlook 2003 w/ sp3. I did exploring and found the HTMLEditor
and HTMLDocument objects, but the 'help' in the object browser wasn't enough
for me. I also saw a reference in Sue Mosher's (first?) book - 'Microsoft
Outlook Programming' to Redemption - but not enough to help with my specific
issue.
Question: Any user can set their email format to 'html' or 'word', true? If
this is the case, then any user could avail themselves of the html.editor or
word.editor solution, whereas with the 'Redemption Library' add on, they
would have to have it installed, true? Without asking you for a lot more help
or the lines of code (!), can you point me to a reference that could tell me
more about the editor objects? Thanks, Charlie
 
A user can set WordMail on or off and also set the format (plain text, RTF
or HTML). You need to check what is being used something like this:

Select Case item.GetInspector.EditorType
Case olEditorHTML
Dim oHTML As MSHTML.HTMLDocument
Set oHTML = item.GetInspector.HTMLEditor
Case olEditorRTF
Case olEditorText
Case olEditorWord
If item.GetInspector.IsWordMail Then
Dim oDoc As Word.Document
Set oDoc = item.GetInspector.WordEditor
End If
End Select

For handling a Word document you need to look at the Word object model and
look at the Selection and Range objects. For handling HTMLDocument items you
need to look in the MSDN library to see how to handle things with that
object.

Redemption is a 3rd party library (I use it all the time) and it provides
much better control of what you need to do in this case. The
Redemption.SafeInspector object has a SelText property that gives you the
selected text. It also has PlainTextEditor and RTFEditor objects that
provide SelStart, SelLength and SelText properties. So using Redemption
allows you to handle both plain text and RTF items. For HTML and WordMail
you continue to use the Word.Document and MSHTML.HTMLDocument objects and
those object models.
 
Ken - great info. Thank you very much. I'll take your advice and get the
Redemption Library.
 
Back
Top