code to print page 1 in landscape, and page 2 in portrait

palaeontology

Active Member
Joined
May 12, 2017
Messages
444
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code to print page 1 of any worksheet with a 5-digit name

Code:
For Each ws In ThisWorkbook.Worksheets
If ws.Name Like "#####" Then
ws.PrintOut from:=1, To:=1
End If
Next ws

However, is it possible to change this code (again for any sheet with a 5-digit name) to print page 1 in landscape, and page 2 in portrait ?

Kind regards,

Chris
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Obtained from the macro recorder :

Code:
For Each ws In ThisWorkbook.Worksheets
    If ws.Name Like "#####" Then
        ws[COLOR=#ff0000].PageSetup.Orientation = xlLandscape[/COLOR]
        ws.PrintOut From:=1, To:=1
        ws[COLOR=#ff0000].PageSetup.Orientation = xlPortrait[/COLOR]
        ws.PrintOut From:=2, To:=2
    End If
Next ws
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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