Microsoft KB Archive/288424

= Limited programmatic access to Word discontiguous selections =

Article ID: 288424

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Office Word 2007
 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q288424



SUMMARY
Microsoft Office Word provides a facility to select multiple discontiguous ranges in a document through its user interface (UI). For example, you can select a range of text in a document, and then, while pressing the CTRL key, select another range of text in that same document to create a discontiguous selection (or multiselection). Microsoft Visual Basic for Applications (VBA) macro code and Automation clients have limited programmatic access to the resulting discontiguous selection. This article discusses these limitations.



Limitations for working with discontiguous selections using the Word object model
 You cannot select a discontiguous range programmatically by using the Word object model. A discontiguous selection may only be created by the user in the Word UI. A Range object cannot contain multiple subranges. Therefore, if the current selection is discontiguous, Selection.Range will return the last subrange that the user selected. When the user selects multiple discontiguous ranges, the following methods and properties of the Selection object apply to all of the subranges in the user's selection:

Selection.Font.Bold

Selection.Font.Italic

Selection.Font.Size

Selection.ClearFormatting

Selection.Copy

Selection.Borders

Selection.Delete

Selection.Style

Selection.Find

NOTE: The Find method works, but you may experience problems keeping the discontiguous ranges selected.

 When the user selects multiple discontiguous ranges, the following members of the Selection object are applied only to the last subrange in the selection:

Selection.Words.Count

Selection.Characters.Count

Selection.Bookmarks.Count

Selection.Text

 Certain members of the Selection object generate one of the following run-time error messages when the selection contains multiple discontiguous ranges:

Error message 1

Run-time error 4605:

This method or property is not available because the current selection is a discontiguous selection.

Error message 2

Run-time error 4605:

This command is not available.

The members that generate one of these errors include the following:

Selection.ConvertToTable

Selection.PageSetup.TextColumns.Count

 There is no way to disable multiselection in Word. However, if you are writing code that works with a selection that the user selects through the UI, you can collapse the selection to the last subrange by using the following:

Selection.ShrinkDiscontiguousSelection

</ul>

Additional query words: prb inf WD2003 WD2007

Keywords: kbinfo KB288424

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.