+ Reply to Thread
Results 1 to 6 of 6

Determine print area for all sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    germany
    MS-Off Ver
    Office 365 Pro (Excel 2016)
    Posts
    45

    Determine print area for all sheets

    Hello,

    I would like to set the print area of all sheets in one file at once.
    Since I do not know how to programm I simply recorded the steps of setting of the print area in one sheet.
    But how do I have to adapt that macro to make it set the print area in all sheets?
    I would like to tell him to select all sheets in the active workbook and do the setting of the print area.
    I tried to elimenate the futile parts of the macro ( I thought the lines ending with a FALSE can be erases),
    but am not sure if I do not miss a lot.

    Sub Print_set()
    '
    ' Print_set Macro
    '

    '
    Range("A1:Y56").SelectAll
    ActiveSheet.PageSetup.PrintArea = "$A$1:$Y$56"
    With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = "&8Druckdatum: &D"
    .CenterFooter = ""
    .RightFooter = "&8CTR.-&F/&A"
    .LeftMargin = Application.InchesToPoints(0.433070866141732)
    .RightMargin = Application.InchesToPoints(0.31496062992126)
    .TopMargin = Application.InchesToPoints(0.590551181102362)
    .BottomMargin = Application.InchesToPoints(0.551181102362205)
    .HeaderMargin = Application.InchesToPoints(0.511811023622047)
    .FooterMargin = Application.InchesToPoints(0.236220472440945)
    .Orientation = xlLandscape
    .Draft = False
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .PrintErrors = xlPrintErrorsDisplayed


    .ScaleWithDocHeaderFooter = True

    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
    End With
    Application.PrintCommunication = True

    End Sub

    Regards

    Pvp

  2. #2
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Determine print area for all sheets

    You can loop through all worksheets like this:

    Sub Print_set() 
        Dim ws As Worksheet 
        For Each ws In ActiveWorkbook.Worksheets
             ws.Select
             Range("A1:Y56").SelectAll
             ActiveSheet.PageSetup.PrintArea = "$A$1:$Y$56"
             With ActiveSheet.PageSetup
             .LeftHeader = ""
             .CenterHeader = ""
             .RightHeader = ""
             .LeftFooter = "&8Druckdatum: &D"
             .CenterFooter = ""
             .RightFooter = "&8CTR.-&F/&A"
             .LeftMargin = Application.InchesToPoints(0.433070866141732)
             .RightMargin = Application.InchesToPoints(0.31496062992126)
             .TopMargin = Application.InchesToPoints(0.590551181102362)
             .BottomMargin = Application.InchesToPoints(0.551181102362205)
             .HeaderMargin = Application.InchesToPoints(0.511811023622047)
             .FooterMargin = Application.InchesToPoints(0.236220472440945)
             .Orientation = xlLandscape
             .Draft = False
             .FirstPageNumber = xlAutomatic
             .Order = xlDownThenOver
             .FitToPagesWide = 1
             .FitToPagesTall = 1
             .PrintErrors = xlPrintErrorsDisplayed
             
             
             .ScaleWithDocHeaderFooter = True
             
             .EvenPage.LeftHeader.Text = ""
             .EvenPage.CenterHeader.Text = ""
             .EvenPage.RightHeader.Text = ""
             .EvenPage.LeftFooter.Text = ""
             .EvenPage.CenterFooter.Text = ""
             .EvenPage.RightFooter.Text = ""
             .FirstPage.LeftHeader.Text = ""
             .FirstPage.CenterHeader.Text = ""
             .FirstPage.RightHeader.Text = ""
             .FirstPage.LeftFooter.Text = ""
             .FirstPage.CenterFooter.Text = ""
             .FirstPage.RightFooter.Text = ""
             End With
             Application.PrintCommunication = True
    
        Next ws 
    End Sub

  3. #3
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Determine print area for all sheets

    You can actually do it all at once....(just realized/learned that one):
    I removed the application.printcommunication = true btw, because it gave an error here.

    Sub print_set()
       Sheets.Select
             With ActiveSheet.PageSetup
             .PrintArea = "$A$1:$Y$56"
             .LeftHeader = ""
             .CenterHeader = ""
             .RightHeader = ""
             .LeftFooter = "&8Druckdatum: &D"
             .CenterFooter = ""
             .RightFooter = "&8CTR.-&F/&A"
             .LeftMargin = Application.InchesToPoints(0.433070866141732)
             .RightMargin = Application.InchesToPoints(0.31496062992126)
             .TopMargin = Application.InchesToPoints(0.590551181102362)
             .BottomMargin = Application.InchesToPoints(0.551181102362205)
             .HeaderMargin = Application.InchesToPoints(0.511811023622047)
             .FooterMargin = Application.InchesToPoints(0.236220472440945)
             .Orientation = xlLandscape
             .Draft = False
             .FirstPageNumber = xlAutomatic
             .Order = xlDownThenOver
             .FitToPagesWide = 1
             .FitToPagesTall = 1
             .PrintErrors = xlPrintErrorsDisplayed
             .ScaleWithDocHeaderFooter = True
             .EvenPage.LeftHeader.Text = ""
             .EvenPage.CenterHeader.Text = ""
             .EvenPage.RightHeader.Text = ""
             .EvenPage.LeftFooter.Text = ""
             .EvenPage.CenterFooter.Text = ""
             .EvenPage.RightFooter.Text = ""
             .FirstPage.LeftHeader.Text = ""
             .FirstPage.CenterHeader.Text = ""
             .FirstPage.RightHeader.Text = ""
             .FirstPage.LeftFooter.Text = ""
             .FirstPage.CenterFooter.Text = ""
             .FirstPage.RightFooter.Text = ""
             End With
        ActiveSheet.Select
    End Sub

  4. #4
    Registered User
    Join Date
    05-23-2011
    Location
    germany
    MS-Off Ver
    Office 365 Pro (Excel 2016)
    Posts
    45

    Re: Determine print area for all sheets

    Hi there,
    thank you very much for your help and your effort. I am not sure why but the code contains a bug. I guess it is due to the fact that the sheets have names?
    I put the code into a module. I attached a screenshot of the VBE including the error message
    Regards
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Determine print area for all sheets

    That is because you have hidden sheets.
    I've made the assumption you dont want to set printarea of the hidden sheets.
    If so, you can go for this:

    Sub print_set()
    
    For Each ws In Sheets
        If ws.Visible Then ws.Select (False)
    Next
    
             With ActiveSheet.PageSetup
             .PrintArea = "$A$1:$Y$56"
             .LeftHeader = ""
             .CenterHeader = ""
             .RightHeader = ""
             .LeftFooter = "&8Druckdatum: &D"
             .CenterFooter = ""
             .RightFooter = "&8CTR.-&F/&A"
             .LeftMargin = Application.InchesToPoints(0.433070866141732)
             .RightMargin = Application.InchesToPoints(0.31496062992126)
             .TopMargin = Application.InchesToPoints(0.590551181102362)
             .BottomMargin = Application.InchesToPoints(0.551181102362205)
             .HeaderMargin = Application.InchesToPoints(0.511811023622047)
             .FooterMargin = Application.InchesToPoints(0.236220472440945)
             .Orientation = xlLandscape
             .Draft = False
             .FirstPageNumber = xlAutomatic
             .Order = xlDownThenOver
             .FitToPagesWide = 1
             .FitToPagesTall = 1
             .PrintErrors = xlPrintErrorsDisplayed
             .ScaleWithDocHeaderFooter = True
             .EvenPage.LeftHeader.Text = ""
             .EvenPage.CenterHeader.Text = ""
             .EvenPage.RightHeader.Text = ""
             .EvenPage.LeftFooter.Text = ""
             .EvenPage.CenterFooter.Text = ""
             .EvenPage.RightFooter.Text = ""
             .FirstPage.LeftHeader.Text = ""
             .FirstPage.CenterHeader.Text = ""
             .FirstPage.RightHeader.Text = ""
             .FirstPage.LeftFooter.Text = ""
             .FirstPage.CenterFooter.Text = ""
             .FirstPage.RightFooter.Text = ""
             End With
        ActiveSheet.Select
    End Sub

  6. #6
    Registered User
    Join Date
    05-23-2011
    Location
    germany
    MS-Off Ver
    Office 365 Pro (Excel 2016)
    Posts
    45

    Re: Determine print area for all sheets

    Thaks a lot. I added to your reputation. Have a good day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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