Microsoft KB Archive/274003

= WD2002: Information (wdActiveEndPageNumber) Property Returns Incorrect Ending Page Number =

Article ID: 274003

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q274003



For a Microsoft Word 2000 version of this article, see 241714.



SYMPTOMS
When you use the wdActiveEndPageNumber Information property in a Word macro, the macro may return an incorrect ending page number.



CAUSE
This problem may occur when all of the following conditions are true:
 * The selected range contains a table.

-and-
 * A page break occurs in the middle of a table row.

-and-
 * The last cell in the row that contains the page break contains text that wraps to a new page.



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: This sample macro may not work correctly in all circumstances.

In the macro, select the range for which you want to retrieve the number of the last page in the range, and use the Selection object instead of the Range object.

If you use the Selection object, it may be a good idea to store the current selection at the beginning of the macro in a Range variable and to set the selection back to its original value at the end of the code that retrieves the page number.

The following sample macro loops through all tables in a document and displays the number of the last page on which each table is located in a message box. It also shows how to store the selection in a Range variable and restore it at the end of the macro. The macro turns the screen updates off (which is optional) and can be used to hide the movement of the selection in the document when the macro is running: Sub GetTableEndPage

Dim tbl As Table Dim rg As Range

' Turn screen updating off. Application.ScreenUpdating = False

'Save the selection in a range object Set rg = Selection.Range Selection.EndKey Unit:=wdStory

'Repaginate ActiveDocument.Repaginate

'Toggle nonprinting characters twice ActiveWindow.ActivePane.View.ShowAll = Not _ ActiveWindow.ActivePane.View.ShowAll

ActiveWindow.ActivePane.View.ShowAll = Not _ ActiveWindow.ActivePane.View.ShowAll

For Each tbl In ActiveDocument.Tables tbl.Select Selection.MoveEnd wdCharacter, -1 MsgBox &quot;Table ends on page &quot; & _ Selection.Information(wdActiveEndPageNumber) Next

'Restore the selection via the saved range object rg.Select

End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The following actions also may help to ensure that the page number is retrieved correctly:  Turn non-printing characters on and off. To do this, follow these steps:  On the Tools menu, click Options. On the View tab, click to select the All check box (under Formatting marks), and then click OK. On the Tools menu, click Options. On the View tab, click to clear the All check box (listed under Formatting marks), and then click OK.</li></ol>

-and-

</li> Repaginate the document. To do this, click Print Preview on the File menu.

-and-</li> Go to the end of the document. To do this, press CTRL+END.</li></ul>

Additional query words: vba WD2002

Keywords: kbbug kbdtacode kbmacro kbnofix kbprogramming KB274003

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.