![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try the following:
For Each ws In Worksheets ws.Select ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address Next
__________________
Kind regards, Al Chara |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|