+ Reply to Thread
Results 1 to 5 of 5

VBA- Print Setting to Apply to Certain Sheets Not Working

Hybrid View

  1. #1
    Registered User
    Join Date
    03-23-2017
    Location
    Texas, United States
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    3

    VBA- Print Setting to Apply to Certain Sheets Not Working

    Hi everyone:

    I'm trying to apply print settings and a few other format settings (row height, hide columns, etc) to only certain sheets in my workbook. However, when I run the code, it stays on the first tab (Summary tab) and applies the code but this is a sheet that I don't want to apply my settings to.

    Sub FormatSheets()
    
        Dim ws As Worksheet
         
        ws.Activate
        For Each ws In ActiveWorkbook.Worksheets
        Select Case ws.Name
            Case "Summary", "ARO"
            Case Else
            
            With ws.PageSetup
                 
                .PrintTitleRows = "$1:$1"
                .Orientation = xlLandscape
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = False
                .LeftMargin = Application.InchesToPoints(0.25)
                .RightMargin = Application.InchesToPoints(0.25)
                .TopMargin = Application.InchesToPoints(0.75)
                .BottomMargin = Application.InchesToPoints(0.75)
                .HeaderMargin = Application.InchesToPoints(0.3)
                .FooterMargin = Application.InchesToPoints(0.3)
                 
            End With
            ws.Cells.Select
            Selection.WrapText = True
            Selection.ColumnWidth = 10
            Selection.EntireRow.AutoFit
            Range("A:A,U:U,W:W,Y:Y,Z:Z,AE:AE,AG:AG,AI:AI,AJ:AJ,AP:AP").EntireColumn.Hidden = True
        
             
        End Select
        Next ws
    
    End Sub

    Any help will be appreciated!
    Last edited by egutierrez7; 03-23-2017 at 07:01 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA- Print Setting to Apply to Certain Sheets Not Working

    Try:

    Sub FormatSheets()
    
    Dim ws As Worksheet
    
    ws.Activate
    For Each ws In ActiveWorkbook.Worksheets
    Select Case ws.name
    Case "Summary", "ARO":GoTo NextSheet
    Case Else
    
    With ws.PageSetup
    
    .PrintTitleRows = "$1:$1"
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.75)
    .BottomMargin = Application.InchesToPoints(0.75)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
    
    End With
    ws.Cells.Select
    Selection.WrapText = True
    Selection.ColumnWidth = 10
    Selection.EntireRow.AutoFit
    Range("A:A,U:U,W:W,Y:Y,Z:Z,AE:AE,AG:AG,AI:AI,AJ:AJ,AP:AP").EntireColumn.Hidden = True
    
    
    End Select
    NextSheet:   Next ws
    
    End Sub
    BTW: Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-23-2017
    Location
    Texas, United States
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    3

    Re: VBA- Print Setting to Apply to Certain Sheets Not Working

    Thank you for the instructions on the Code rule. I updated it.

    As far as your suggestion, it's still formatting that first sheet and doesn't move to the sheets I'm asking it to apply the formatting to. :\

  4. #4
    Registered User
    Join Date
    03-23-2017
    Location
    Texas, United States
    MS-Off Ver
    MS Office Professional Plus 2010
    Posts
    3

    Re: VBA- Print Setting to Apply to Certain Sheets Not Working

    I updated my code after the PageSetup End With and it seems to be working now. Apparently, my "ws.Activate" code was in the wrong spot. I appreciate your help!

    Sub FormatSheets()
    
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Worksheets
    Select Case ws.Name
    Case "Summary", "ARO": GoTo NextSheet
    Case Else
    
    With ws.PageSetup
    
    .PrintTitleRows = "$1:$1"
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.75)
    .BottomMargin = Application.InchesToPoints(0.75)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
    
    End With
    ws.Activate
    ws.Cells.Select
    Selection.WrapText = True
    Selection.ColumnWidth = 10
    Selection.EntireRow.AutoFit
    Range("A:A,U:U,W:W,Y:Y,Z:Z,AE:AE,AG:AG,AI:AI,AJ:AJ,AP:AP").EntireColumn.Hidden = True
    
    
    End Select
    NextSheet:   Next ws
    
    End Sub

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA- Print Setting to Apply to Certain Sheets Not Working

    I tested this version and it worked:

    Sub FormatSheets()
    
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    Select Case ws.name
    Case "Summary", "ARO"
    GoTo NextSheet
    Case Else
    
    With ws.PageSetup
    
    .PrintTitleRows = "$1:$1"
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.75)
    .BottomMargin = Application.InchesToPoints(0.75)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
    
    End With
    ws.Cells.WrapText = True
    ws.Columns.ColumnWidth = 10
    ws.Rows.AutoFit
    ws.Range("A:A,U:U,W:W,Y:Y,Z:Z,AE:AE,AG:AG,AI:AI,AJ:AJ,AP:AP").EntireColumn.Hidden = True
    
    
    End Select
    NextSheet:   Next ws
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA- Applying Print Settings to Certain Sheets is Not Working
    By egutierrez7 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 03-23-2017, 05:48 PM
  2. [SOLVED] Want to apply code to all sheets available in workbook except two sheets with fast working
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-28-2017, 08:55 AM
  3. Apply Worksheet Print Properties to all Sheets
    By Rico1919 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2014, 09:59 PM
  4. automate setting the print area of a workbook having 57 sheets on a A4 size paper
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-25-2013, 04:17 AM
  5. Setting Print Area across multiple sheets?
    By tekman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2011, 10:40 PM
  6. Apply Print Settings to Multiple Sheets via MACRO
    By ShaneBell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2009, 08:48 PM
  7. How do I apply the same print settings to all sheets in a workbk
    By Excel Print Entire Workbook Settings in forum Excel General
    Replies: 0
    Last Post: 09-15-2005, 10:05 AM

Tags for this Thread

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