I am attempting to find the usable page size so that I can set Page Breaks in VBA. I have it working with the following code. But it is only guess work. I would like to be able to know when I am going to overflow the bottom of the usable space rather that guessing at how big it is. There is probably a setting that tells me that but can't seem to find it.
'*******************************************
'*******************************************
Sub UTY_Get_Page_Height()
'*******************************************
'*******************************************
' Control_Page_Height_Begin
' Control_Page_Height_End
' Control_Row_Highest
' Control_Row_Lowest
'Stop
Set Control_Page_Height_Begin = ActiveSheet.Range("A1:F" & Control_Row_Lowest)
Set Control_Page_Height_End = ActiveSheet.Range("A1:F" & Control_Row_Highest)
If Control_Page_Height_End.Height - _
Control_Page_Height_Begin.Height > 450 Then
Control_Row_Type_Hold = Control_Row_Type
ActiveSheet.HPageBreaks.Add Before:=Range("A" & Control_Row_Highest + 1)
UTY_Set_Page_Headers
Control_Row_Type = Control_Row_Type_Hold
Control_Row_Lowest = Control_Row_Highest
End If
End Sub
I have looked at TopMargin and BottomMargin but they do not report the values that I need (want). If I knew the total size of a page (Portrait or Landscape) then I could use these margins. Current I have margins set to .25 inches which returns a value of 18 (unconverted to inches) and am in Landscape.
If I knew the total size of a page, then I could determine when to set the Page Break ... I believe.
Any help or other ideas would be most helpful.
Thanks to all
'*******************************************
'*******************************************
Sub UTY_Get_Page_Height()
'*******************************************
'*******************************************
' Control_Page_Height_Begin
' Control_Page_Height_End
' Control_Row_Highest
' Control_Row_Lowest
'Stop
Set Control_Page_Height_Begin = ActiveSheet.Range("A1:F" & Control_Row_Lowest)
Set Control_Page_Height_End = ActiveSheet.Range("A1:F" & Control_Row_Highest)
If Control_Page_Height_End.Height - _
Control_Page_Height_Begin.Height > 450 Then
Control_Row_Type_Hold = Control_Row_Type
ActiveSheet.HPageBreaks.Add Before:=Range("A" & Control_Row_Highest + 1)
UTY_Set_Page_Headers
Control_Row_Type = Control_Row_Type_Hold
Control_Row_Lowest = Control_Row_Highest
End If
End Sub
I have looked at TopMargin and BottomMargin but they do not report the values that I need (want). If I knew the total size of a page (Portrait or Landscape) then I could use these margins. Current I have margins set to .25 inches which returns a value of 18 (unconverted to inches) and am in Landscape.
If I knew the total size of a page, then I could determine when to set the Page Break ... I believe.
Any help or other ideas would be most helpful.
Thanks to all
Last edited: