INFO: Limited Programmatic Access to Word 2002 Discontiguous Selections (288424)



The information in this article applies to:

  • Microsoft Word 2002

This article was previously published under Q288424

SUMMARY

Word 2002 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.

MORE INFORMATION

Limitations for Working with Discontiguous Selections Using the Word Object Model

  • You cannot select a discontiguous range programmatically by using the Word 2002 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 when the selection contains multiple discontiguous ranges:
    Run-time error 4605:
    This method or property is not available because the current selection is a discontiguous selection.

    -or-

    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


Modification Type:MajorLast Reviewed:4/3/2001
Keywords:kbDSupport kbinfo KB288424