Gustav Brock
Gustav at cactus.dk
Sat Sep 6 16:30:08 CDT 2008
Hi Stephen Don't use Select except if you really wish to have the WorkSheet visible and select something for the user. /gustav >>> stephen at bondsoftware.co.nz 06-09-2008 09:45 >>> The code segment below takes around 10 seconds to run. The worksheet has been just created in code, an embedded chart has been built on the worksheet (again, code), and the code below is the 'prettying up' bit. Yep, to get it, I recorded a macro in Excel and then commented out the bits I didn't want/didn't work. I put some rudimentary time checks at random places in this segment. Embedded in the sample, I have put the elapsed time it took to get to the indicated line. Any ideas? The rest of it runs really fast on a 6-year-old PC (768MB, WinXP SP2, Processor x86 Family 6 Model 8 Stepping 0 AuthenticAMD ~1529 Mhz) but I can't see why this is happening. I am generating a couple of hundred sheets at a time, so the slowness is not trivial. TIA Stephen Bond ' finally build print specs xlWs.Range("A1").Select With xlWb.ActiveSheet.PageSetup .PrintArea = "" .PrintTitleRows = "" .PrintTitleColumns = "" .LeftHeader = "&6&Z&F!&A" ' 0 seconds .CenterHeader = "&""Arial,Bold""&16&A" .RightHeader = "&6Printed &D &T" .LeftFooter = "&6Prepared by Stephen Bond for " & conUser1 .CenterFooter = "&""Arial,Bold""&16&A" .RightFooter = "&6based on an idea by J McKinlay, Southland Boys' High School" ' 3 seconds ' .LeftMargin = Application.InchesToPoints(0.75) ' .RightMargin = Application.InchesToPoints(0.75) ' .TopMargin = Application.InchesToPoints(0.75) ' .BottomMargin = Application.InchesToPoints(0.75) ' .HeaderMargin = Application.InchesToPoints(0.5) ' .FooterMargin = Application.InchesToPoints(0.5) .PrintHeadings = False .PrintGridlines = True .PrintComments = xlPrintNoComments ' 5 seconds ''''' .PrintQuality = -4 .CenterHorizontally = True .CenterVertically = False .Orientation = xlLandscape .Draft = False ' 7 seconds .PaperSize = xlPaperA4 .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = False ' 10 seconds .FitToPagesWide = 1 .FitToPagesTall = 1 .PrintErrors = xlPrintErrorsDisplayed ' 10 seconds End With