Outlook 2002 SP3 and Outlook 2003 block Inspector.HTMLEditor and Inspector.WordEditor properties. Redemption.SafeInspector object allows to work around these blocks, plus it adds several objects and properties that are missing from the Outlook Object Model. You can use SafeInspector object to read or set the selected text for any kind of Outlook editor (Plain Text, RTF, Word and HTML), access PlainTextEditor and RTFEditor objects, format the RTF text, etc.

To use the SafeInspector object, you need to create an instance of the Redemption.SafeInspector object, set its Item property to an instance of the Outlook.Inspector object, then access its properties and methods:

The example below displays the selected text in an active Inspector

'retrieve selected text from the Inspector
set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
MsgBox "You have selected: " & sInspector.SelText

Setting the SelText property will insert the specified text at the current caret position.

'retrieve selected text from the Inspector
set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
sInspector.SelText = "<this text had just been inserted>"

See below for more SafeInspector examples.

SafeInspector objects:

SafeInspector

    PlainTextEditor

    RTFEditor

        TextAttributes

        ParagraphAttributes

SafeInspector sample code


SafeInspector object properties

Property

Comments


Item - object, read/write

Must be set to an instance of the Outlook.Inspector object before using the SafeInspector object

 

HTMLEditor - returns IHTMLDocument object, read only

This is the equivalent of the Inspector.HTMLEditor object in OOM.

 

Note that Outlook 2007 always uses Word editor, so HTMLEditor under Outlook 2007 will always return NULL.

 

WordEditor - returns Word.Document object, read only

This is the equivalent of the Inspector.WordEditor object in OOM

 

SelText - string, read/write

Returns/set the plain text version of the selection

 

Text - string, read/write

Returns the plain text in the inspector

 

PlainTextEditor - returns PlainTextEditor object, read-only

Returns the object representing the plain text editor. Note that due to the internal implementation of the plain text/RTF editor in Outlook, this object will work both for the plain text and RTF inspectors.

 

Note that Outlook 2007 always uses Word editor, so PlainTextEditor under Outlook 2007 will always return NULL.

 

RTFEditor -  returns RTFEditor object, read-only

Returns the object representing the RTF editor. Note that due to the internal implementation of the plain text/RTF editor in Outlook, this object will work both for the plain text and RTF inspectors.

 

Note that Outlook 2007 always uses Word editor, so RTFEditor under Outlook 2007 will always return NULL.

 


 

PlainTextEditor object - Note that Outlook 2007 always uses Word editor, hence SafeInspector.PlainTextEditor under Outlook 2007 will always return NULL.

 

Property or method

Comments


Clear method

Deletes all text from the editor

 

ClearSelection method

Deletes the selected text from the editor

 

ClearUndo method

Clears the undo buffer so that no changes to the text can be backed out

 

CopyToClipboard method

Copies the selected text in the inspector to the Clipboard.

 

CutToClipboard method

Copies the selected text to the Clipboard in clear text format and then deletes the selection

 

PasteFromClipboard method

Pastes the contents of the Clipboard into the memo, replacing the current selection.

 

SelectAll method

Selects all text in the editor.

 

Undo method

Backs out all changes in the undo buffer.

 

CaretPosX - integer, read-write property

Indicates the horizontal position of the caret in the client area of the editor.

 

CaretPosY - integer, read-write property

Indicates the vertical position of the caret in the client area of the editor.

 

CanUndo - boolean, read-only property

Indicates whether the editor contains changes that can be backed out.

 

HideSelection - boolean, read-write property

Determines whether the visual indication of the selected text remains when focus shifts from the editor to another control

 

ReadOnly - boolean, read-write property

Determines whether the user can change the text of the editor

 

SelLength - integer, read-write property

Specifies the number of characters that are selected.

 

SelStart - integer, read-write property

Specifies the position of the first selected character in the text.

 

SelText - string, read-write property

Specifies the selected portion of the editor's text.

 

Text - string, read-write property

Specifies the text string that is displayed in the editor

 

Handle - integer, read-only property

Returns the editor window handle (HWND). You can use this property if you need to send Windows messages directly to the editor bypassing the PlainTextEditor object.

 


 

 

RTFEditor object. Note that Outlook 2007 always uses Word editor, hence SafeInspector.RtfEditor under Outlook 2007 will always return NULL.

In addition to the properties and methods exposed by the PlainTextEditor object, RTFEditor object exposes the following properties:

 

Property

Comments


RTFSelText - string, read-write property

Specifies the selected portion of the editor's RTF text. Important note: this property is only available if your code is running inside of the outlook.exe process space; that is your code must be a COM addin or run in the Outlook VBA editor.

 

RTFText - string, read-write property

Specifies the RTF text string that is displayed in the editor. Important note: this property is only available if your code is running inside of the outlook.exe process space; that is your code must be a COM addin or run in the Outlook VBA editor.

 

DefAttributes - returns TextAttributes object, read-only property

Use DefAttributes to discover or set the default font characteristics that the RTF editor uses for newly inserted text. These are the characteristics of the text before any special attributes have been applied. Once any special attributes are applied to a portion of text, no text from that point on is considered to have the default attributes, even if the attributes match the DefAttributes.

For example, if an RTF editor has had no attributes applied, the entire text has the default attributes. Selecting a portion of text in the middle and applying a specific attribute (such as a font change) results in three sections: a first section with the default attributes, a middle section with the applied attribute, and a final section with a non-default set of attributes that match the default attributes. Changing the DefAttributes property affects only the first section.

When inserting new text, the font characteristics of the new text will match the font characteristics at the cursor position, or, if the typing replaces a selection, the font characteristics of the selected text. New text will only have the default attributes when typed into the section of text that has the default attribute

 

SelAttributes - returns TextAttributes object, read-only property

Use SelAttributes to discover or set the font characteristics of the currently selected text. SelAttributes is a TextAttributes object, which specifies characteristics such as font face, color, size, style, and pitch. To change a single attribute of the currently selected text, read SelAttributes, and set one of its properties. To change all of the attributes of the currently selected text, set SelAttributes to a TextAttributes object that represents the desired configuration of attributes. If no text is selected, SelAttributes represents the attributes of the cursor position.

When inserting new text, the font characteristics of the new text will match SelAttributes.

 

ParagraphAttributes - returns ParagraphAttributes object, read-only property

Specifies the formatting information for the current paragraphs

 


TextAttributes object

Property

Comments


BackColor - integer, read/write Indicates the background color of the text

 

Charset - integer, read/write

Specifies the character set of the font

 

Color- integer, read/write

Indicates the foreground color of the text

 

Height- integer, read/write

Specifies the height of the font in pixels.

 

Name- string, read/write

Specifies the typeface of the font.

 

Pitch - FontPitch enumeration, read/write

Specifies whether the characters in the font all have the same width - fpDefault (0), fpVariable (1), fpFixed (2).

 

Protected - boolean, read/write

Indicates whether the text is protected

 

Size - integer, read/write

Specifies the height of the font in points.

 

Style - FontStyle object, see comments

Determines whether the font is normal, italic, underlined, bold, or strikeout. Size property returns the FontStyle object, which has 4 properties (all boolean read/write) - Bold,  Italic, Underline, Strikeout.

 

ConsistentAttributes - object, see comments

Indicates which of the properties of the TextAttributes object are consistent throughout the text of the current selection in the RTF editor. ConsistentAttributes object has 8 properties (all boolean, read-only): Bold, Color, Face, Italic, Size, Strikeout, Underline, Protected.

 


ParagraphAttributes object

Property

Comments


Alignment - TextAlignment enumeration, read/write

Specifies how text is aligned within a paragraph: taLeftJustify (0), taCenter (1), taRightJustify (2)

FirstIndent - integer, read/write

Specifies the indent, in pixels, of the first line of the paragraph relative to the left margin.

LeftIndent - integer, read/write

Specifies the indent, in pixels, of the paragraph relative to the left margin.

RightIndent - integer, read/write

Specifies the indent, in pixels, of the paragraph relative to the right margin.

Numbering - NumberingStyle enumeration, read/write

Specifies whether the paragraph is one of a set of bulleted paragraphs: nsNone (0), nsBullet (1).


 


SafeInspector Object Sample Code

Display the selected text in the active Inspector:

'retrieve selected text from the Inspector
set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
MsgBox "You have selected: " & sInspector.SelText

Insert text at the current cursor position:

set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
sInspector.SelText = "<this text had just been inserted>"

Change the currently selected text to an upper case:

set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
SelText = sInspector.SelText
if Len(SelText) = 0 Then
  MsgBox "You must select text first"
Else
  sInspector.SelText = UCase(sInspector.SelText)
End If

Bold the currently selected text (RTF Editor only). For other kinds of editors (HTML or Word), you will need to use DOM or Word Object Model respectively.

set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
set RTFEditor = sInspector.RTFEditor
if (RTFEditor is Nothing) or (sInspector.EditorType <> olEditorRTF) Then
  MsgBox "This sample only works for the RTF Editor"
Else
  RTFEditor.SelAttributes.Style.Bold = TRUE
End If