Optimizing print areas

DavidB

Active Member
Joined
Oct 21, 2002
Messages
253
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi there

I like using the fit to page option within Excel, however, a report that a third party tool generates is sometimes better displayed in landscape rather than portrait and vice versa. I would like to be able to change this quickly / automatically. What i envisage is something like auto-fit for fonts within a cell.

Does anyone know of some VBA code to determine and change the page orientation to result in the larger area being occupied in a printed output? (This might be able to be determined by the zooming percentage??)

Thanks DavidB
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Assuming you want to fit to one page :
Code:
Sub SetPageOrientation()
Dim ls%, pt%
With ActiveSheet.PageSetup
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .Orientation = xlLandscape
    ExecuteExcel4Macro ("PAGE.SETUP(,,,,,,,,,,,,{#N/A,#N/A})")
    ls = .Zoom
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .Orientation = xlPortrait
    ExecuteExcel4Macro ("PAGE.SETUP(,,,,,,,,,,,,{#N/A,#N/A})")
    pt = .Zoom
    If pt < ls Then
        .Zoom = ls
        .Orientation = xlLandscape
    End If
End With
End Sub

You might find this helpful https://groups.google.com/forum/#!topic/microsoft.public.excel.programming/8wZfCNzEreA
 
Last edited:
Upvote 0
Thanks Footoo

That is exactly what I am looking for.

Cheers DavidB
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top