Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I would like some help with this print macro please. When the spreadsheet was smaller it printed landscape. Now the spreadsheet is larger it prints portrait and over 3 pages. Could someone point me to the area I need to change to make it print landscape again or have some compression?
Option ExplicitSub Print_Page()
With ThisWorkbook.Worksheets("Vendors")
.Activate
'Highlight the used area of the spreadsheet
.Range(.Cells(2, 2), .Cells(WorksheetFunction.CountA(.Range(.Cells(13, 2), _
.Cells(.UsedRange.Rows(.UsedRange.Rows.Count).Row, 2))) + 12, _
.UsedRange.Columns(.UsedRange.Columns.Count).Column)).Select
Selection.PrintOut
.Range("A1").Select
End With
End SubThank you for your time!

Landscape? That's one extra line.
Sub Print_Page()
With ThisWorkbook.Worksheets("Vendors")
.Activate
.PageSetup.Orientation = xlLandscape
'Highlight the used area of the spreadsheet
.Range(.Cells(2, 2), .Cells(WorksheetFunction.CountA(.Range(.Cells(13, 2), _
.Cells(.UsedRange.Rows(.UsedRange.Rows.Count).Row, 2))) + 12, _
.UsedRange.Columns(.UsedRange.Columns.Count).Column)).PrintOut
End With
End Sub

Razor2.3 answered the Landscape portion of your question, so I'll add some sample compression code.
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End WithA subtle, yet key point to notice about 2.3's suggested code:
You'll notice he nevers *selects* the range to be printed. Rarely (I won't say never) do you need to Select a range or sheet to perform an action on it. If you record a macro, it will write the selection code, but that is a very inefficient method. As can be seen from 2.3's code, you can almost always eliminate the ".Select" and subsequent "Selection." and perform most actions directly on the range.

Thank you I am really learning a great deal of very useful information from you chaps.
I am very grateful. Thanks

![]() |
double underline in word
|
Filling Blank cell
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |