Word VBA, End of File
In this article I will explain how you can check if you’ve reached the end of a word document using VBA. In the articles below I’ve explained how to get the current page and line number the cursor is on:
Using the code below you can get the last line and page number of the document:
By comparing the current position of the cursor with last line and last page we can determine whether we have reached the last line or not.
Note: The line numbers obtained are relative to the page. That means that the line number starts from “1” at the start of each page. That is why we need to have both the page number and the line number to determine if we have reached the end of the document or not.
A complete example of using this method has been used in the article below:
- Word VBA, Get Current Page Number
- Word VBA, Get Current Line Number
- Word VBA, Move Cursor to End of Document