Results 1 to 9 of 9

Thread: Excel: Apply print formatting to all sheets at once

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Excel: Apply print formatting to all sheets at once

    I excel if I record a macro of doing this...
    or do it manually (Select all sheets.. the pagesetup) it hits all the sheets.

    In my VB app it doesnt hit anything but the first sheet!???

    VB Code:
    1. Private Sub PrintSetup()
    2.  
    3. For X = 1 To WKBK.Worksheets.Count
    4.     WKBK.Worksheets(X).Select Replace:=False
    5. Next
    6.     WKBK.Worksheets(1).Activate
    7.     With WKBK.ActiveSheet.PageSetup
    8.         .PrintTitleRows = HeadRow '"$3:$12"
    9.         .PrintTitleColumns = HeadCol '"$A:$A"
    10.         .LeftHeader = ""
    11.         .CenterHeader = ""
    12.         .RightHeader = ""
    13.         .LeftFooter = ""
    14.         .CenterFooter = ""
    15.         .RightFooter = "Page &P"
    16.         .LeftMargin = Application.InchesToPoints(xlsLeft)
    17.         .RightMargin = Application.InchesToPoints(xlsRight)
    18.         .TopMargin = Application.InchesToPoints(xlsTop)
    19.         .BottomMargin = Application.InchesToPoints(xlsBottom)
    20.         .HeaderMargin = Application.InchesToPoints(xlsHeader)
    21.         .FooterMargin = Application.InchesToPoints(xlsFooter)
    22.         .PrintHeadings = False
    23.         .PrintGridlines = False
    24.         .PrintComments = xlPrintNoComments
    25.         .PrintQuality = 600
    26.         .CenterHorizontally = False
    27.         .CenterVertically = False
    28.         .Orientation = xlLandscape
    29.         .Draft = False
    30.         .PaperSize = xlPaperLetter
    31.         .FirstPageNumber = xlAutomatic
    32.         .Order = xlDownThenOver
    33.         .BlackAndWhite = False
    34.         .Zoom = xlsZoom
    35.     End With
    36. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel: Apply print formatting to all sheets at once

    Your pagesetup only works with one sheet (WKBK.Worksheets(1).Activate), to make it work with more than one, simply loop thru as you are doing for the select (which by the way, isnt needed), eg:
    VB Code:
    1. Private Sub PrintSetup()
    2.  
    3. For X = 1 To WKBK.Worksheets.Count
    4.     With WKBK.Worksheets(X).PageSetup
    5.         .PrintTitleRows = HeadRow '"$3:$12"
    6. ...
    7.         .Zoom = xlsZoom
    8.     End With
    9. Next
    10.  
    11. End Sub
    It is best not to use ActiveSheet (or similar) as any users working in Excel can change the ActiveSheet

  3. #3
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: Excel: Apply print formatting to all sheets at once

    Edit: Didn't notice someone replied...should've hit the refresh button before posting...oops

    Well if you want all the worksheets to have the same setup, I don't think you need to select each sheet if you're going to Activate it, so get rid of that line. And also place your Next statement at the end of the Formatting.

    And the reason it only selects the first worksheet I can't explain (from your macro recording), but just replace 1 with X and it will setup each sheet the same.


    VB Code:
    1. Private Sub PrintSetup()
    2.  
    3. For X = 1 To WKBK.Worksheets.Count
    4.     WKBK.Worksheets(X).Activate
    5.  
    6.     With WKBK.ActiveSheet.PageSetup
    7.         .PrintTitleRows = HeadRow '"$3:$12"
    8.         .PrintTitleColumns = HeadCol '"$A:$A"
    9.         .LeftHeader = ""
    10.         .CenterHeader = ""
    11.         .RightHeader = ""
    12.         .LeftFooter = ""
    13.         .CenterFooter = ""
    14.         .RightFooter = "Page &P"
    15.         .LeftMargin = Application.InchesToPoints(xlsLeft)
    16.         .RightMargin = Application.InchesToPoints(xlsRight)
    17.         .TopMargin = Application.InchesToPoints(xlsTop)
    18.         .BottomMargin = Application.InchesToPoints(xlsBottom)
    19.         .HeaderMargin = Application.InchesToPoints(xlsHeader)
    20.         .FooterMargin = Application.InchesToPoints(xlsFooter)
    21.         .PrintHeadings = False
    22.         .PrintGridlines = False
    23.         .PrintComments = xlPrintNoComments
    24.         .PrintQuality = 600
    25.         .CenterHorizontally = False
    26.         .CenterVertically = False
    27.         .Orientation = xlLandscape
    28.         .Draft = False
    29.         .PaperSize = xlPaperLetter
    30.         .FirstPageNumber = xlAutomatic
    31.         .Order = xlDownThenOver
    32.         .BlackAndWhite = False
    33.         .Zoom = xlsZoom
    34.     End With
    35. Next
    36. End Sub
    HTH




    If you find any of my posts of good help, please rate it

  4. #4

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel: Apply print formatting to all sheets at once

    I have had that.. its too slow! the workbooks typically have 30+ sheets...
    i excel it works though...??
    Macro code
    VB Code:
    1. Sheets(Array("Output 36", "Output 35", "Output 34", "Output 33", "Output 32", _
    2.         "Output 31", "Output 30", "Output 29", "Output 28", "Output 27", "Output 26", _
    3.         "Output 25", "Output 24", "Output 23", "Output 22", "Output 21", "Output 20", _
    4.         "Output 19", "Output 18", "Output 17", "Output 16", "Output 15", "Output 14", _
    5.         "Output 13", "Output 12")).Select
    6.     Sheets("Output 36").Activate
    7.     Sheets(Array("Output 11", "Output 10", "Output 9", "Output 8", "Output 7", _
    8.         "Output 6", "Output 5", "Output 4", "Output 3", "Output 2", "Output 1")).Select _
    9.         Replace:=False
    10.     With ActiveSheet.PageSetup
    11.         .LeftHeader = ""
    12.         .CenterHeader = "&A"
    13.         .RightHeader = ""
    14.         .LeftFooter = ""
    15.         .CenterFooter = "Page &P"
    16.         .RightFooter = ""
    17.         .LeftMargin = Application.InchesToPoints(0)
    18.         .RightMargin = Application.InchesToPoints(0)
    19.         .TopMargin = Application.InchesToPoints(0)
    20.         .BottomMargin = Application.InchesToPoints(0)
    21.         .HeaderMargin = Application.InchesToPoints(0)
    22.         .FooterMargin = Application.InchesToPoints(0)
    23.         .PrintHeadings = False
    24.         .PrintGridlines = False
    25.         .PrintComments = xlPrintNoComments
    26.         .PrintQuality = 600
    27.         .CenterHorizontally = False
    28.         .CenterVertically = False
    29.         .Orientation = xlLandscape
    30.         .Draft = False
    31.         .PaperSize = xlPaperLetter
    32.         .FirstPageNumber = xlAutomatic
    33.         .Order = xlDownThenOver
    34.         .BlackAndWhite = False
    35.         .Zoom = 50
    36.     End With
    all pages get the formatting!???
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel: Apply print formatting to all sheets at once

    In that case, try replicating the code you got from the macro:
    VB Code:
    1. Private Sub PrintSetup()
    2.  
    3. Dim SheetNames() as String
    4. ReDim SheetNames(1 To WKBK.Worksheets.Count) as String
    5.     For X = 1 To WKBK.Worksheets.Count
    6.        SheetNames(X) = WKBK.Worksheets(X).Name
    7.     Next
    8.     WKBK.Worksheets(1).Activate
    9.     WKBK.Worksheets(SheetNames).Select Replace:=False
    10.     With WKBK.ActiveSheet.PageSetup
    11. ...

  6. #6

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel: Apply print formatting to all sheets at once

    oo.. didnt try it as an array in the select (I was adding to the selection 1 at a time)... hmmm

    be right back
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel: Apply print formatting to all sheets at once

    wait... now thats strange. If you manually select all sheets... the do page setup it works.. but the recorded macro only hits one sheet.

    I may have to loop through...yuk its so slow!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: Excel: Apply print formatting to all sheets at once

    Is this procedure being performed everytime you print?

    If so, maybe you should just place this code in a workbook_open event. You'll only have to set it once (unless you manually changed it or another macro changes it after the workbook has been opened).




    If you find any of my posts of good help, please rate it

  9. #9

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel: Apply print formatting to all sheets at once

    no. I created an external app that does a number of things like renaming sheets, print formatting, hiding/unhinding sheets.. depending on the workbook opened

    I think I'll just have to loop through all the sheets bah!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width