How to automatically change print orientation from landscape to portrait and portrait to landscape using VBA. Watch the video below:
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:
Dim r As Range
Set r = ActiveSheet.UsedRange
If r.Width > 595.3 Then
.Orientation = xlLandscape
.Orientation = xlPortrait
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.