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. To prevent this problem, add code to select the last cell used in the worksheet before the code uses the
Location property of horizontal or vertical page breaks. For example, use the following code to select the end cell, use the
Location property, and then reselect the original active cell:
Sub CheckPageBreaks()
'Set object "currcell" equal to active cell.
Set currcell = ActiveCell
'Select the last cell on the worksheet that has data.
Range("IV65536").Select
'Include code with Location property here.
x = ActiveSheet.HPageBreaks(2).Location.Address
MsgBox x
'Example sets x equal to address of second horizontal page break.
'Then message box displays the address of the page break.
'Select original active cell.
currcell.Select
End Sub
After the
Location property is calculated, you may again select the original active cell. If you use code to scroll between the first and last cell, or select the last cell and immediately reselect the starting cell, the error may still occur. The screen must redraw and the
Location property be calculated for the workaround to be effective. If you use the above code with
Application.ScreenUpdating = False
to prevent screen redraw, the problem still occurs.