Word VBA: Moving Cursor to Beginning of Document by Bookmark

This macro moves an cursor to the beginning of a Word document.

Macro Example

Sub PositionCursorToStartOfDocument()
 
  ActiveDocument.Bookmarks("\StartOfDoc").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.Bookmarks (Document.Bookmarks)

  ActiveDocument.Bookmarks...

The ActiveDocument.Bookmarks (Document.Bookmarks property) returns a Bookmarks collection object that represents all the bookmarks in the active document.

obj-Word-Document-Bookmarks

Bookmarks(“\StartOfDoc”) (Bookmarks.Item)

  ActiveDocument.Bookmarks("\StartOfDoc")...

The Bookmarks(“\StartOfDoc”) (Bookmarks.Item method) returns an individual Bookmark object from the Bookmarks collection.

obj-Word-Bookmarks-Item

Because the Item method is a default member of the Bookmarks collection object, we can omit the .Item.

So, the Bookmarks(“\StartOfDoc”) is equal Bookmarks.Item(“\StartOfDoc”).

And the Bookmarks(“\StartOfDoc”) returns the beginning of the document by the predefined bookmark named “\StartOfDoc”.

Bookmarks(“\StartOfDoc”).Select (Bookmark.Select)

  ActiveDocument.Bookmarks("\StartOfDoc").Select

Finally, we can select the active page by the Range.Delete method.

obj-Word-Bookmark-Select

Sub PositionCursorToStartOfDocument()
 
  ActiveDocument.Bookmarks("\StartOfDoc").Select

End Sub

obj-Word-Range-Delete

Properties

http://www.relief.jp/itnote/archives/word-vba-selecting-start-documents.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007