
Tips.Net > WordTips Home > Macros > VBA Examples > Jumping to the Start or End of a Document
Summary: Macros often need to jump around in a document in order to complete their processing. If you need your macro to jump to the beginning or end of a document, the task is easy to do if you know the proper programming method to use. This tip shows you exactly how easy it is. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
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
Tip #120 applies to Microsoft Word versions: 97 2000 2002 2003
Save Time! WordTips has been published weekly since early 1997. Past issues are available in convenient WordTips archives. Have your own enhanced archive of WordTips at your fingertips, available to use at any time!
Check out WordTips Archives today!
Learn to search for and replace text, formatting, graphics, and special characters the easy way with WordTips: Find and Replace. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips