Class TextRetrievalMode (Word VBA)

The class TextRetrievalMode represents options that control how text is retrieved from a Range object. To use a TextRetrievalMode class variable it first needs to be instantiated, for example


Dim trm as TextRetrievalMode
Set trm = ActiveDocument.Range.TextRetrievalMode

Duplicate

Returns a read-only TextRetrievalMode object that represents options related to retrieving text from a Range object.

You can use the Duplicate property to pick up the settings of all the properties of a duplicated object. You can assign the object returned by the Duplicate property to another object of the same type to apply those settings all at once. Before assigning the duplicate object to another object, you can change any of the properties of the duplicate object without affecting the original text.


Dim trmDuplicate As TextRetrievalMode
Set trmDuplicate = ActiveDocument.Range.TextRetrievalMode.Duplicate

IncludeFieldCodes

True if the text retrieved from the specified range includes field codes.

The default value is the same as the setting of the Field codes option on the View tab in the Options dialog box (Tools menu) until this property has been set. Use the Text property with a Range object to retrieve text from the specified range.


Dim rngTemp As Range 
 
Set rngTemp = ActiveDocument.Paragraphs(1).Range 
 
rngTemp.TextRetrievalMode.IncludeFieldCodes = False 
MsgBox rngTemp.Text

IncludeHiddenText

True if the text retrieved from the specified range includes hidden text.

The default value is the same as the current setting of the Hidden text option on the View tab in the Options dialog box (Tools menu) until this property has been set. Use the Text property with a Range object to retrieve text from the specified range.


Dim rngTemp As Range 
 
Set rngTemp = ActiveDocument.Sentences(1) 
 
rngTemp.TextRetrievalMode.IncludeHiddenText = True 
MsgBox rngTemp.Text

ViewType

Returns or sets the view for the TextRetrievalMode object. Possible return values are wdConflictView, wdMasterView - A master view, wdNormalView - A normal view, wdOutlineView - An outline view, wdPrintPreview - A print preview view, wdPrintView - A print view, wdReadingView - A reading view, wdWebView - A Web view.

Changing the view for the TextRetrievalMode object doesn't change the display of a document on the screen. Instead, it determines which characters in the document will be included when a range is retrieved.


Set myText = ActiveDocument.Content 
myText.TextRetrievalMode.ViewType = wdOutlineView 
Msgbox myText