Range.TextRetrievalMode Property (Word)
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Range.TextRetrievalMode Property (Word)

Returns a TextRetrievalMode object that controls how text is retrieved from the specified Range. Read/write.

expression .TextRetrievalMode

expression A variable that represents a Range object.

This example retrieves the selected text (excluding any hidden text) and inserts it at the beginning of the third paragraph in the active document.

If Selection.Type = wdSelectionNormal Then 
 Set Range1 = Selection.Range 
 Range1.TextRetrievalMode.IncludeHiddenText = False 
 Set Range2 = ActiveDocument.Paragraphs(2).Range 
 Range2.InsertAfter Range1.Text 
End If

This example retrieves and displays the first three paragraphs as they appear in outline view.

Set myRange = ActiveDocument.Range(Start:=ActiveDocument _ 
 .Paragraphs(1).Range.Start, _ 
myRange.TextRetrievalMode.ViewType = wdOutlineView 
MsgBox myRange.Text

This example excludes field codes and hidden text from the range that refers to the selected text. The example then displays the text in a message box.

If Selection.Type = wdSelectionNormal Then 
 Set aRange = Selection.Range 
 With aRange.TextRetrievalMode 
 .IncludeHiddenText = False 
 .IncludeFieldCodes = False 
 End With 
 MsgBox aRange.Text 
End If
© 2016 Microsoft