Computing.Net > Forums > Office Software > Print macro

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Print macro

Reply to Message Icon

Name: toast (by NoIdea)
Date: June 12, 2008 at 01:31:41 Pacific
OS: XP Pro
CPU/Ram: 2.3Ghtz / 1gig
Product: EMachines 580
Comment:

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 Explicit

Sub 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 Sub

Thank you for your time!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: June 12, 2008 at 03:27:08 Pacific
Reply:

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


0

Response Number 2
Name: DerbyDad03
Date: June 12, 2008 at 06:34:55 Pacific
Reply:

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 With

A 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.


0

Response Number 3
Name: toast (by NoIdea)
Date: June 12, 2008 at 16:27:45 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


double underline in word Filling Blank cell



Post Locked

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


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Print macro

Printing Macro www.computing.net/answers/office/printing-macro/1488.html

Printing Excel Pages www.computing.net/answers/office/printing-excel-pages/2860.html

Print Current Page --> Macro www.computing.net/answers/office/print-current-page-macro/4890.html