Word VBA: Selecting All Text by WholeStory

This Word VBA macro selects all text in an active document.

Macro Example

Sub SelectAllText_Selection_WholeStory()

  ActiveDocument.Range(0, 0).Select
  Selection.WholeStory

End Sub

Description

[Application.]ActiveDocument

  ActiveDocument...

The [Application.]ActiveDocument property returns an active Document object.

obj-Word-Application-ActiveDocument

Because the ActiveDocument property is a member of the Word.Global class, we can omit the Application property.

obj-Word-ActiveDocument

ActiveDocument.Range (Document.Range)

  ActiveDocument.Range...

The ActiveDocument.Range (Document.Range method) returns a Range object that represents a contiguous area in the document.

obj-Word-Document-Range

The Document.Range method specifies the range by parameters. The 1st parameter means starting position, the 2nd parameter means ending position.

The following code refers to the range that starts at the beginning of the active document.

  ActiveDocument.Range(0, 0)...

Range(0, 0).Select (Range.Select)

The Range.Select method selects the specified range. So the following code selects the beginning of an active document.

  ActiveDocument.Range(0, 0).Select

Expand Selection

Sub...

  ActiveDocument.Range(0, 0).Select
  Selection.WholeStory

The 4th line expands a selection to include the entire story.

[Application.]Selection

  Selection...

The [Application.]Selection property returns the Selection object that represents a selected range or the insertion point.

Selection.WholeStory

  Selection.WholeStory

The Selection.WholeStory method expands a selection to include the entire story.

Sub SelectAllText_Selection_WholeStory()

  ActiveDocument.Range(0, 0).Select
  Selection.WholeStory

End Sub

Properties

http://www.relief.jp/itnote/archives/word-vba-select-whole-story.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007