Consulting

Results 1 to 2 of 2

Thread: Loop Format (Not Looping)

  1. #1
    VBAX Newbie
    Joined
    Jul 2018
    Posts
    1
    Location

    Loop Format (Not Looping)

    Hello,

    I am trying to use the following loop to format all the sheets in the workbook. It seems to only be applying to the active worksheet. Please tell me what I am doing wrong.

    Thank you!
    Sub PL_Format()
    
    
    Dim WS_Count As Integer
    Dim I As Integer
    
    
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    
    For I = 1 To WS_Count
        With ActiveSheet.PageSetup
            .PrintTitleRows = "$1:$7"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(1)
            .BottomMargin = Application.InchesToPoints(0.25)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintComments = xlPrintNoComments
            .PrintQuality = 360
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = False
            .PrintErrors = xlPrintErrorsDisplayed
        End With
    Next I
    
    
    End Sub
    Last edited by Paul_Hossler; 07-22-2018 at 04:11 PM. Reason: Added CODE tags

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Welcome to the forums

    Take a minute to read the FAQ's, including the part about using CODE tags

    Anyway, ...

    It's applying it to just the active sheet because that's what you told it to do

    With ActiveSheet.PageSetup


    You probably wanted

    With ActiveWorkbook.Worksheets(I).PageSetup
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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