Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Jumping to the Start or End of a Document.

Jumping to the Start or End of a Document

Written by Allen Wyatt (last updated September 20, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


8

When you are creating a macro, there are many times you want to move to the beginning or end of your document. The exact syntax for how you do this depends on whether you are using WordBasic or VBA. If you are programming in VBA, you use the HomeKey and EndKey methods of the Selection object. For instance, the following two lines will move the cursor to the beginning of the document, and then to the end:

Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdStory

If you want to select everything from the current position to the beginning or end of the document, you simply add the Extend method. The following will select everything from the current location to the beginning of the document:

Selection.HomeKey Unit:=wdStory, Extend:=wdExtend

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (120) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Jumping to the Start or End of a Document.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Speeding Up Large Worksheets

If your worksheet gets large enough, you may notice a severe slowdown when it is recalculated. This tip provides some ...

Discover More

Determining the Number of Bookmarks Defined in a Document

If you develop a macro that needs to work with bookmarks defined in a document, it is inevitable that you will need a way ...

Discover More

Importing a Text File and Inserting after a Bookmark

Word macros are a great way to automate some of the ways in which you create documents. If you have a need to insert the ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (menu)

Determining if Num Lock is On

Need to know if the Num Lock key is on or off? You can use a short bit of macro code to figure out the state of the key.

Discover More

Understanding the For ... Next Structure

Spend any time creating Word macros, and sooner or later you will need to repeat some of your programming code a certain ...

Discover More

Determining How Many Windows are Open

You can open multiple documents at the same time in Word, and each document occupies its own document window. Here's a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2020-06-10 10:11:01

Vitor Carvalho

So, please, may you tell me why in an VBA access subroutine, when i try to execute the code below
why did i get a compiler error on the statements ".Selection.HomeKey" or ".Selection.EndKey", because the system apparently doesen't recognize the "wdStory" and "wdExtend" parameters.

... .... ....
Set oApp = CreateObject("Word.Application") 'Cria e abre o objeto Word
With oApp
.Documents.Open (vDotx)
.Selection.HomeKey Unit:=wdStory
.Selection.EndKey Unit:=wdStory, Extend:=wdExtend
.Selection.Copy
End With


2019-07-01 14:08:11

Ilya

Thanks, very helpful!


2019-03-04 03:40:48

Vikas

Thanks!
this is what I have been looking for.


2018-04-12 13:08:09

Brian Smith

Thank you for posting - -his worked perfectly!


2017-12-13 14:46:54

Jamie

Just what I needed, thanks! Works perfect. Everyone else wanted to use SendKeys.


2016-08-14 08:43:59

Mike

It would be helpful if you did this in non expert computer mode.

I am not an expert just a user.


2016-07-24 10:46:38

Paul Creamer

I'm trying to use this tip..

but what I have is a activedocument.


What I am literally trying to do is to take a template.doc (basically a new page1) to go above 1200+ jobdocs that are existing docs.. These existing docs all have tables in the worddoc.

Converting them to text.. is not a option, per the information is such that it would be messy.

So when I try whatever ive tried.. I always end up with template.doc in the topmost/leftmost cell of the table.. instead of above the table.

Ive tried sendkey,homekey both and even other ideas.. yet even with above


I am assuming the tip above is working and that its what I try to insert template that I'm goofing on.

Any ideas?


2015-03-30 07:38:30

Tarik

Thanks for the tip


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.