![]() |
What's the VBA syntax to replicate this?
When a user wants to make a global update to the print setup in a
multi-tab workbook, they can group all the sheets, make the change, and it reflects in each of the grouped tabs. I'm trying to replicate this using VBA, but I can't make it work. I've tried ActiveWorkbook.Sheets.Select Sheets("Home").Activate 'tried it with and without this line With ActiveSheet.PageSetup .setup parameters snipped End With .... but this changes only the first of the grouped tabs. I've written code that changes each tab's setup individually, but that takes 80 to 90 seconds to run. In desperation I recorded the steps in a macro, which derives this code to group tabs: Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select Since the number and names of tabs will vary from user to user, I wrote code to recreate the list of tab names with quotes, commas, and spaces then using the variable name in that syntax, like this Sheets(Array(TabNamesList)).Select .... to no avail- it generates an error. What is the syntax to replicate the process of manually grouping tabs? Thanks! |
What's the VBA syntax to replicate this?
This will work HTH
Sub FMFormatSheets() ' ' Macro recorded 10/14/2004; Updated 8/8/2006 by Dennis Burgess, CPA ' [Purpose is to format a consistant Header Footer & settings for all sheets in the workbook] ' ' Dim EachSheet As Worksheet Dim myLastRow As Long, myLastCol As Long Dim MyPreviousWorkSheet As Worksheet Set MyPreviousWorkSheet = ActiveSheet With Application ' .Calculation = xlAutomatic ' .MaxChange = 0.001 .ScreenUpdating = False End With For Each EachSheet In ActiveWorkbook.Worksheets With EachSheet.PageSetup myLastRow = EachSheet.Cells.SpecialCells(xlLastCell).Row myLastCol = EachSheet.Cells.SpecialCells(xlLastCell).Column EachSheet.PageSetup.PrintArea = "" ' Resets or clears PrintArea .PrintArea = Range(Cells(1, 1), Cells(myLastRow, myLastCol)).Address .PrintTitleRows = "" ' Example "$1:$3" .PrintTitleColumns = "" ' Example "$A:$C" .LeftHeader = "" ' Example Same as Footer info below .CenterHeader = _ "&""Arial,Bold""&18Company, Inc.&""Arial,Regular""&10" & Chr(10) & "&14Excel WorkSheet Review" & Chr(10) & "&12[&F] Tab: &A" .RightHeader = "" .LeftFooter = "&8&Z" .CenterFooter = "&8" & Chr(10) & "Personal xxx" .RightFooter = "&8Page &P of &N" .LeftMargin = Application.InchesToPoints(0.25) .RightMargin = Application.InchesToPoints(0.25) .TopMargin = Application.InchesToPoints(1#) .BottomMargin = Application.InchesToPoints(0.6) .HeaderMargin = Application.InchesToPoints(0.21) .FooterMargin = Application.InchesToPoints(0.38) .PrintHeadings = False ' True or False .PrintGridlines = False ' True or False .PrintComments = xlPrintNoComments .PrintQuality = 600 .CenterHorizontally = True ' True or False .CenterVertically = False ' True or False .Orientation = xlLandscape .Draft = False ' True or False .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False ' True or False .Zoom = False ' True or False .FitToPagesWide = 1 .FitToPagesTall = 25 End With Next EachSheet For Each EachSheet In ActiveWorkbook.Worksheets EachSheet.Activate ActiveWindow.View = xlPageBreakPreview ' ActiveWindow.View = xlNormalView ActiveWindow.Zoom = 75 Next EachSheet MyPreviousWorkSheet.Select Range("A1").Select MsgBox "Process Completed! Press OK to Continue" End Sub wrote: When a user wants to make a global update to the print setup in a multi-tab workbook, they can group all the sheets, make the change, and it reflects in each of the grouped tabs. I'm trying to replicate this using VBA, but I can't make it work. I've tried ActiveWorkbook.Sheets.Select Sheets("Home").Activate 'tried it with and without this line With ActiveSheet.PageSetup .setup parameters snipped End With ... but this changes only the first of the grouped tabs. I've written code that changes each tab's setup individually, but that takes 80 to 90 seconds to run. In desperation I recorded the steps in a macro, which derives this code to group tabs: Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select Since the number and names of tabs will vary from user to user, I wrote code to recreate the list of tab names with quotes, commas, and spaces then using the variable name in that syntax, like this Sheets(Array(TabNamesList)).Select ... to no avail- it generates an error. What is the syntax to replicate the process of manually grouping tabs? Thanks! |
What's the VBA syntax to replicate this?
Dennis- Thanks for your response. I wrote code similar to yours- the
process of changing each sheet individually takes 80+/- seconds in this workbook, which I'm trying to shorten with the Group All idea. Gord- I'm trying to allow users the ability to change paper size from Letter to A4. Is there any validity to the idea of creating a string (such as "Sheet1", "Sheet2", "Sheet3" etc) with the variable name TabNamesList to serve as an argument in this line: Sheets(Array(TabNamesList)).Select It generated an error on previous tries but I'm clutching at straws, now. Thanks! |
All times are GMT +1. The time now is 06:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com