+ Reply to Thread
Results 1 to 6 of 6

printing on backpage, but changing the orientation to landscape

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    printing on backpage, but changing the orientation to landscape

    I have the below code to print specific pages on the backside, it works, but if someone can help me code it to print "map" in landscape orientation (ONLY 'map" sheet in orientation
    Private Sub BackPrint()
    Dim sCurrentPrinter As String
    Dim ws As Worksheet
    Dim sheetsToPrint1, sheetsToPrint2, sheetsToPrint3, sheetsToPrint4 As Variant
    
    
    sCurrentPrinter = Application.ActivePrinter
    
    Application.ActivePrinter = "MF220 Series on Ne02:"
    
    IgnorePrintAreas:=False
    
    'move maps sheet to end
    Sheets("Map").Move After:=Sheets(Sheets.Count)
    
    Dim sheetsToPrint As Sheets
    
    Set sheetsToPrint1 = Worksheets(Array("QUOTE", "Map"))
    Set sheetsToPrint2 = Worksheets(Array("YYYYY", "Map"))
    Set sheetsToPrint3 = Worksheets(Array("TTTTT", "Map"))
    Set sheetsToPrint4 = Worksheets(Array("Customer"))
    
        
      For Each ws In sheetsToPrint1
            With ws.PageSetup
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = 1
            End With
        Next ws
        
    End Sub
    Right now its printing on on the backside, and it working fine, but if someone can help me change the orientation to Landscape on "Map".. and Sheets (QUOTE, TTTTT, YYYYY, Customer) in portrait

  2. #2
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: printing on backpage, but changing the orientation to landscape

    Add the orientation line of code as per below:

    With ws.PageSetup
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .Orientation=switch(ws.name="Map",xlLandscape,1<2,xlportrait)
    
    End With
    Last edited by deadlyduck; 12-10-2023 at 06:47 PM.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: printing on backpage, but changing the orientation to landscape

    that worked! thank you again deadlyduck!
    so that i learn, what does the 1<2 do? 1 is for portrait and 2 for landscape? because i couldnt see that in the syntax
    Last edited by chubbychub; 12-10-2023 at 07:30 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    540

    Re: printing on backpage, but changing the orientation to landscape

    1<2 is my way of forcing a TRUE outcome- the switch statement needs one of the pairs of items to be true in order to know what to do. I could possibly have the word TRUE instead of 1<2.

  5. #5
    Forum Contributor
    Join Date
    10-24-2012
    Location
    San Diego, USA
    MS-Off Ver
    Excel 2019
    Posts
    871

    Re: printing on backpage, but changing the orientation to landscape

    thank you for the explanation deadlyduck, can you make the code with margins 0 at top, 0 at the bottom, 0 left, and 0 right? but only for sheets "map", while the rest of the sheets stays the same? how would i add those properties to only 'map'?

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,251

    Re: printing on backpage, but changing the orientation to landscape

    For example (in the code you can specify page settings for each sheet separately):
    Option Explicit
    
    Sub B_ack_Pr_int()
        Dim i As Long, j As Long
        Dim sCurPrntr As String
        Dim Customer, Installers, Map, Quote, Whouse
        Dim s, s1, s2, s3, s4
        
        sCurPrntr = Application.ActivePrinter
        
        'Schema:
        'Sheet = Array(Sheetname, Orientation, Zoom, FitToPagesWide, FitToPagesTall, PaperSize, PrintQuality, _
                       FirstPageNumber, LeftMargin, RightMargin, TopMargin, BottomMargin, HeaderMargin, _
                       FooterMargin, CenterHorizontally, CenterVertically, LeftHeader, CenterHeader, _
                       RightHeader, LeftFooter, CenterFooter, RightFooter, OddAndEvenPagesHeaderFooter, _
                       EvenPageLeftHeaderText, EvenPageCenterHeaderText, EvenPageRightHeaderText, _
                       EvenPageLeftFooterText, EvenPageCenterFooterText, EvenPageRightFooterText, _
                       DifferentFirstPageHeaderFooter, FirstPageLeftHeaderText, FirstPageCenterHeaderText, _
                       FirstPageRightHeaderText, FirstPageLeftFooterText, FirstPageCenterFooterText, _
                       FirstPageRightFooterText, ScaleWithDocHeaderFooter, AlignMarginsHeaderFooter, PrintArea, _
                       PrintTitleRows, PrintTitleColumns, PrintGridlines, BlackAndWhite, Draft, PrintHeadings, _
                       PrintComments, PrintErrors, Order)
        
        Customer = Array("Customer", xlPortrait, 100, 1, 1, xlPaperLetter, 600, xlAutomatic, _
                  1, 1, 1, 1, 1, 1, False, False, _
                  "", "", "", "", "", "", False, "", "", "", "", "", "", False, "", "", "", "", "", "", True, True, _
                  "", "", "", False, False, False, False, xlPrintNoComments, xlPrintErrorsDisplayed, xlDownThenOver)
        
        Installers = Array("Installers", xlPortrait, 100, 1, 1, xlPaperLetter, 600, xlAutomatic, _
                  1, 1, 1, 1, 1, 1, False, False, _
                  "", "", "", "", "", "", False, "", "", "", "", "", "", False, "", "", "", "", "", "", True, True, _
                  "", "", "", False, False, False, False, xlPrintNoComments, xlPrintErrorsDisplayed, xlDownThenOver)
        
        Map = Array("Map", xlLandscape, 100, 1, 1, xlPaperLetter, 600, xlAutomatic, _
                  0, 0, 0, 0, 0, 0, False, False, _
                  "", "", "", "", "", "", False, "", "", "", "", "", "", False, "", "", "", "", "", "", True, True, _
                  "", "", "", False, False, False, False, xlPrintNoComments, xlPrintErrorsDisplayed, xlDownThenOver)
        
        Quote = Array("QUOTE", xlPortrait, 100, 1, 1, xlPaperLetter, 600, xlAutomatic, _
                  1, 1, 1, 1, 1, 1, False, False, _
                  "", "", "", "", "", "", False, "", "", "", "", "", "", False, "", "", "", "", "", "", True, True, _
                  "", "", "", False, False, False, False, xlPrintNoComments, xlPrintErrorsDisplayed, xlDownThenOver)
        
        Whouse = Array("Whouse", xlPortrait, 100, 1, 1, xlPaperLetter, 600, xlAutomatic, _
                  1, 1, 1, 1, 1, 1, False, False, _
                  "", "", "", "", "", "", False, "", "", "", "", "", "", False, "", "", "", "", "", "", True, True, _
                  "", "", "", False, False, False, False, xlPrintNoComments, xlPrintErrorsDisplayed, xlDownThenOver)
        
        s1 = Array(Quote, Map)
        s2 = Array(Whouse, Map)
        s3 = Array(Installers, Map)
        s4 = Array(Customer)
        s = Array(s1, s2, s3, s4)
        
        For i = LBound(s) To UBound(s)
            For j = LBound(s(i)) To UBound(s(i))
                Page_Set_Up s(i)(j)
            Next
        Next
    End Sub
    
    Sub Page_Set_Up(psu)
        Application.PrintCommunication = False
            With Sheets(psu(0)).PageSetup
                .Orientation = psu(1)
                If psu(2) = False Then
                    .FitToPagesWide = psu(3)
                    .FitToPagesTall = psu(4)
                Else
                    .Zoom = psu(2)
                End If
                .PaperSize = psu(5)
                .PrintQuality = psu(6)
                .FirstPageNumber = psu(7)
                .LeftMargin = Application.InchesToPoints(psu(8))
                .RightMargin = Application.InchesToPoints(psu(9))
                .TopMargin = Application.InchesToPoints(psu(10))
                .BottomMargin = Application.InchesToPoints(psu(11))
                .HeaderMargin = Application.InchesToPoints(psu(12))
                .FooterMargin = Application.InchesToPoints(psu(13))
                .CenterHorizontally = psu(14)
                .CenterVertically = psu(15)
                .LeftHeader = psu(16)
                .CenterHeader = psu(17)
                .RightHeader = psu(18)
                .LeftFooter = psu(19)
                .CenterFooter = psu(20)
                .RightFooter = psu(21)
                .OddAndEvenPagesHeaderFooter = psu(22)
                If psu(22) = True Then
                    .EvenPage.LeftHeader.Text = psu(23)
                    .EvenPage.CenterHeader.Text = psu(24)
                    .EvenPage.RightHeader.Text = psu(25)
                    .EvenPage.LeftFooter.Text = psu(26)
                    .EvenPage.CenterFooter.Text = psu(27)
                    .EvenPage.RightFooter.Text = psu(28)
                End If
                .DifferentFirstPageHeaderFooter = psu(29)
                If psu(29) = True Then
                    .FirstPage.LeftHeader.Text = psu(30)
                    .FirstPage.CenterHeader.Text = psu(31)
                    .FirstPage.RightHeader.Text = psu(32)
                    .FirstPage.LeftFooter.Text = psu(33)
                    .FirstPage.CenterFooter.Text = psu(34)
                    .FirstPage.RightFooter.Text = psu(35)
                End If
                .ScaleWithDocHeaderFooter = psu(36)
                .AlignMarginsHeaderFooter = psu(37)
                .PrintArea = psu(38)
                .PrintTitleRows = psu(39)
                .PrintTitleColumns = psu(40)
                .PrintGridlines = psu(41)
                .BlackAndWhite = psu(42)
                .Draft = psu(43)
                .PrintHeadings = psu(44)
                .PrintComments = psu(45)
                .PrintErrors = psu(46)
                .Order = psu(47)
            End With
        Application.PrintCommunication = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Printing common backpage with different margins
    By jilaba in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-27-2020, 01:04 PM
  2. [SOLVED] Set size to A4, orientation to landscape and margins to narrow and then Save As PDF
    By waimea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2018, 12:03 PM
  3. [SOLVED] Print Orientation from Portrait to landscape?
    By bralew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2017, 07:20 AM
  4. Save Excel Charts to PDF in Landscape Orientation and Fit Page
    By huntethic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2017, 05:55 PM
  5. Print Macro - Landscape Orientation Graph
    By Oliver Rogers in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-28-2011, 07:37 AM
  6. Trouble with landscape page orientation
    By barbinhb in forum Excel General
    Replies: 2
    Last Post: 03-11-2010, 04:17 PM
  7. landscape and letter orientation same doc?
    By godfather_77 in forum Word Formatting & General
    Replies: 1
    Last Post: 02-22-2009, 07:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1