Word VBA: Selecting All Text by the Document.StoryRanges

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

Macro Example

Sub SelectAllText_Document_StoryRanges()
  
  ActiveDocument.StoryRanges(wdMainTextStory).Select

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.StoryRanges (Document.StoryRanges)

  ActiveDocument.StoryRanges...

The ActiveDocument.StoryRanges (Document.StoryRanges property) returns the StoryRanges collection object.

obj-Word-Document-StoryRanges

StoryRanges(wdMainTextStory) (StoryRanges.Item(wdMainTextStory))

  ActiveDocument.StoryRanges(wdMainTextStory)...

The StoryRanges.Item method returns a single story of a range or selection as a Range object.

obj-Word-StoryRanges-Item

And the StoryRanges.Item(wdMainTextStory) represents the main text story.

The Item method is a default member of the StoryRanges collection object. We can see a little blue marble beside its icon in the Object Browser. So we can omit the .Item .

StoryRanges(wdMainTextStory).Select (Range.Select)

  ActiveDocument.StoryRanges(wdMainTextStory).Select

Finally, the StoryRanges(wdMainTextStory).Select (Range.Select) method selects the main text story range.

Sub SelectAllText_Document_StoryRanges()
  
  ActiveDocument.StoryRanges(wdMainTextStory).Select

End Sub

Properties

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

Apply To

  • Word 2013
  • Word 2010
  • Word 2007