May 20, 2021

Automatically Change Print Orientation

How to automatically change print orientation from landscape to portrait and portrait to landscape using VBA. Watch the video below:

Automatically Change Print Orientation

To save paper it would be a good idea if we could change the print orientation from portrait to landscape automatically based on our worksheet data. With the present data in our worksheet if we try to print in the portrait mode, we would get 6 pages of printouts and the details will be so divided that printing in this manner makes little sense. If we, however, print in the landscape mode we get 4 pages of printouts with all the details as required. Now doing such an activity manually every time can be time consuming. We can automate the process using VBA. Below is the complete macro code to change the print orientation automatically:

Sub ChangePrintOrientationAutomatically()
Dim r As Range

Set r = ActiveSheet.UsedRange

With ActiveSheet.PageSetup

If r.Width > 595.3 Then

.Orientation = xlLandscape


.Orientation = xlPortrait

End If

End With


End Sub

There are 28.35 points in a centimeter. Since the width of an A4 size page is 21 cm there are a total of 595.3 points in the whole width.

Automatically Change Print Orientation
Automatically Change Print Orientation

One thought on “Automatically Change Print Orientation

Comments are closed.