Macro does not return all selected text as expected in Word (292138)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Word 2002

This article was previously published under Q292138

SYMPTOMS

In Microsoft Office Word, when you use the Text property of the Selection object to return selected non-contiguous text with a Microsoft Visual Basic for Applications (VBA) macro, not all of the selected text is returned to the Immediate window of the Visual Basic Editor as expected.

CAUSE

This behavior occurs when you use the CTRL key and the mouse to select non-contiguous strings of text, and then attempt to programmatically use or view the selected text in the Immediate window by running a macro similar to the following:
Sub ProccessMultiSelect()

   Debug.Print Selection.Text

End Sub
				
Only the last text selection is stored in the Selection.Text property. Earlier selections are overwritten each time a new selection is made. Therefore, only the last can be returned to the Immediate window.

WORKAROUND

To work around this issue, select only one contiguous text string each time that you use the Text property of the Visual Basic Selection object.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbprb KB292138