bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Macros > VBA Examples > Jumping to the Start or End of a Document

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


More Power! For some people, the prospect of creating Word macros can be scary. WordTips: The Macros can help you conquer your fears and you'll discover you're much more confident and productive as you make Word do exactly what you want. This is an invaluable source for learning macros. You are introduced to the topic in bite-sized chunks, pulled from past issues of WordTips. Learn at your own pace, exactly the way you want.
 
Check out WordTips: The Macros today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Vital News Home

WordTips FAQ
WordTips Premium

Learn Access Now

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

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)