What paper are you using ? how many lines can you print using this paper ? landscape or portrait ?
Setting ONE page is difficuly, especially because it depends on printer drivers, so, if you're gonna use this FOR yourself, it wouldn't be THAT hard, but if you need it to be "generic", well, that's a little harder...
Juan Pablo G.
Try this code
Sub PrintAreaOnePage()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim x As Integer, y As Integer
With ActiveSheet.PageSetup
' find number of columns
Do
x = x + 1
.PrintArea = ActiveCell.Resize(1, x).Address
Loop Until ActiveSheet.VPageBreaks.Count = 1
x = x - 1
Do
y = y + 1
.PrintArea = ActiveCell.Resize(y, 1).Address
Loop Until ActiveSheet.HPageBreaks.Count = 1
y = y - 1
.PrintArea = ActiveCell.Resize(y, x).Address
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Gary
A slightly faster alternative (no loop) ......
Sub PrintAreaOnePage()
Dim rw%, col%
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address & ":IV65536"
rw = ExecuteExcel4Macro("INDEX(GET.DOCUMENT(64)," & 2 & ")") - 1
col = ExecuteExcel4Macro("INDEX(GET.DOCUMENT(65)," & 2 & ")") - 1
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address & ":" & Cells(rw, col).Address
End Sub
Dim x As Integer, y As Integer With ActiveSheet.PageSetup ' find number of columns Do x = x + 1 .PrintArea = ActiveCell.Resize(1, x).Address Loop Until ActiveSheet.VPageBreaks.Count = 1 x = x - 1 Do y = y + 1 .PrintArea = ActiveCell.Resize(y, 1).Address Loop Until ActiveSheet.HPageBreaks.Count = 1 y = y - 1 End With Application.DisplayAlerts = True Application.ScreenUpdating = True
Doesn't work. Needs revising. Later ... (nt)
Dim x As Integer, y As Integer With ActiveSheet.PageSetup ' find number of columns Do x = x + 1 .PrintArea = ActiveCell.Resize(1, x).Address Loop Until ActiveSheet.VPageBreaks.Count = 1 x = x - 1 Do y = y + 1 .PrintArea = ActiveCell.Resize(y, 1).Address Loop Until ActiveSheet.HPageBreaks.Count = 1 y = y - 1 End With Application.DisplayAlerts = True Application.ScreenUpdating = True
Sub PrintAreaOnePage()
Dim rw%, col%, x#, y%
If Intersect(ActiveCell, ActiveSheet.UsedRange) Is Nothing Then
MsgBox "The activecell is not within the sheet's used range"
Exit Sub
End If
ActiveSheet.PageSetup.PrintArea = ""
x = ActiveCell.Row
y = ActiveCell.Column
On Error Resume Next
rw = ExecuteExcel4Macro("INDEX(GET.DOCUMENT(64)," & 1 & ")") + x - 2
If rw = 0 Then
rw = Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
End If
col = ExecuteExcel4Macro("INDEX(GET.DOCUMENT(65)," & 1 & ")") + y - 2
If col = 0 Then
col = Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End If
On Error GoTo 0
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address & ":" & Cells(rw, col).Address
End Sub
Dim x As Integer, y As Integer With ActiveSheet.PageSetup ' find number of columns Do x = x + 1 .PrintArea = ActiveCell.Resize(1, x).Address Loop Until ActiveSheet.VPageBreaks.Count = 1 x = x - 1 Do y = y + 1 .PrintArea = ActiveCell.Resize(y, 1).Address Loop Until ActiveSheet.HPageBreaks.Count = 1 y = y - 1