Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Set Print Area Dynamically for all worksheets in workbook

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    359
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I can't get this to work? Am a novice at VBA, trying to learn, though. Please help me correct the code below. THANKS!

    For Each ws In Worksheets

    ws.select
    Range(A1,Range(H65536).End(xlUp).Address).Select

    ActiveSheet.PageSetup.PrintArea = Selection

    Next ws

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following:

    For Each ws In Worksheets
    ws.Select
    ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address
    Next
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    359
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Al,

    Thanks! IT works!

    Here's my code. Had it exclude certain worksheets. But it takes a couple of seconds for each worksheet. Is because it's looping though the excluding certain worksheets part? How can I get it to exclude them once and for all and then set print areas for all other sheets??

    Also, I want to just set the print area to print on ONE page only.
    Can I just use only

    .FitToPagesWide = 1
    .FitToPagesTall = 1

    and exclude the rest?
    From .LeftHeader = ""
    to .Zoom = False

    THANKS!

    CODE:
    For Each ws In Worksheets
    If ws.Name <> "Summary" Then
    If ws.Name <> "Conversion Factors" Then
    If ws.Name <> "Coatings - All" Then
    If ws.Name <> "PivotTable" Then
    If ws.Name <> "Calculations" Then
    If ws.Name <> "PivotTable-Constituents&Coating" Then
    ws.Select
    ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

    With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.75)
    .RightMargin = Application.InchesToPoints(0.75)
    .TopMargin = Application.InchesToPoints(1)
    .BottomMargin = Application.InchesToPoints(1)
    .HeaderMargin = Application.InchesToPoints(0.5)
    .FooterMargin = Application.InchesToPoints(0.5)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlPortrait
    .Draft = False
    .PaperSize = xlPaperLetter
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With

    End If
    End If
    End If
    End If
    End If
    End If

    Next ws
    End Sub


Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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