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.
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.
Learn more about Allen...
In other issues of WordTips you learn how to use the HomeKey and EndKey methods to move to the beginning or end of a document within a macro. These work great, provided the insertion point is within the main body of the document when the macro is executed. It doesn't always work as expected if the insertion point is someplace else, however.
For instance, if your insertion point is located in a header or footer, then HomeKey and EndKey will result in moving to the beginning or end of the header or footer, not the entire document. To make absolutely sure you go to where you expect in the document, this means you need to use a different VBA approach. The following code line will take you to the beginning of the document, regardless of your insertion point location:
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst
Likewise, to jump to the end of the real document you can use the following:
The lack of elegance and symmetry between the two commands is unfortunate, but without knowing where the insertion point is located, these commands are safer than using HomeKey and EndKey alone.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (826) applies to Microsoft Word 97, 2000, 2002, and 2003.
Take Control! Master the real power behind Word! Successfully master the secrets of powerful formatting and create documents that stand out from the rest. Best of all, you can create documents that are easy to maintain and quick to change. Check out Word 2007 Styles and Templates today!