XL: PageBreak Property Does Not Work as Expected

ID: Q134731


The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0


SYMPTOMS

In Microsoft Excel, the Visual Basic, Applications Edition, PageBreak property may not return the correct addresses for all page breaks in a worksheet.


CAUSE

When you insert a manual page break, all automatic page break addresses are changed accordingly. A Visual Basic procedure that verifies the addresses of page breaks will return only information about the manual page break addresses and the original automatic page break addresses; new automatic page break addresses will not be returned.


WORKAROUND

Using the Microsoft Excel 4.0 macro function "GET.DOCUMENT(64)" will return the address of all page breaks in the document. The following macro shows demonstrates how to use this Microsoft Excel 4.0 macro function in a Visual Basic for Applications procedure. The following procedure will return an array of all page breaks in a document.

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.


Sub TestPageBreaks()

Dim NumberOfBreaks As Integer   'Total Number of Page Breaks in a Document
Dim Counter As Integer          'Generic Counter
Dim BreaksArray()               'Array of Row numbers of each page break

   'Get Number of PageBreaks
   NumberOfBreaks = _
      Application.ExecuteExcel4Macro("COLUMNS(GET.DOCUMENT(64))")

   'Resize Array to Hold All PageBreaks Row Numbers
   ReDim BreaksArray(1 To NumberOfBreaks)

   'Loop to fill the Array with PageBreaks Row Numbers
   For Counter = 1 To NumberOfBreaks
       BreaksArray(Counter) = _
          Application _
          .ExecuteExcel4Macro("INDEX(GET.DOCUMENT(64)," & _
           Counter & ")")
   Next

   'Loop to Show All PageBreaks Row Numbers
   For Counter = 1 To NumberOfBreaks
      MsgBox "There is a Page Break at Row: " & BreaksArray(Counter)
   Next
End Sub 


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


REFERENCES

For more information about the PageBreak property, click the Index tab in Microsoft Excel Help, type the following text

pagebreak
and then double-click the selected text to go to the "PageBreak Property" topic.

Additional query words: 5.00c PageBreak Automatic Page Break

Keywords : kbprg
Version : WINDOWS:5.0,5.0c,7.0; winnt:5.0
Platform : WINDOWS winnt
Issue type :


Last Reviewed: October 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.