Microsoft KB Archive/241714

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

Article ID: 241714

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q241714



For a Microsoft Word 2002 version of this article, see 274003.



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

This problem can occur in any of the following macro samples, but it may not occur in all circumstances: Sub GetTableEndPage

Dim myRange

Set myRange = ActiveDocument.Tables(1).Range MsgBox myRange.Information(wdActiveEndPageNumber)

End Sub

-or-

Sub GetTableEndPage

Dim i As Integer

For i = 1 To ActiveDocument.Tables.Count ActiveDocument.Tables(i).Select MsgBox "Table " & i & " ends on page " _ & Selection.Information(wdActiveEndPageNumber) Next

End Sub

-or-

Sub GetTableEndPage

For Each tbl In ActiveDocument.Tables MsgBox "Table ends on page " & _ Selection.Information(wdActiveEndPageNumber) Next

End Sub



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.

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

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 "Table ends on page " & _ 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 may also 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(listed 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

Keywords: kbbug kbdtacode kbmacro kbnofix kbprogramming KB241714

-

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

© Microsoft Corporation. All rights reserved.