LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default need to speed up some page formatting code

in addition, you don't have to list the values you AREN'T
changing.......
for instance, these are default:

With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 400
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
End With

so you could considerably shorten your code by eliminating the ones
you aren't changing, i.e.,
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.PrintQuality = 400
.Orientation = xlLandscape
.Zoom = 100
End With

these are the only values you are changing in your code.
hth!
susan


On Apr 10, 2:06 pm, Mike wrote:
Try this I changed From Worksheet(1) to ActiveSheet this way what ever sheet
is active you could run macro
Sub helpSpeedupFormating()
Application.ScreenUpdating = False 'Turn off to help speed things up

ActiveSheet.Cells.Font.Name = "Arial Narrow"
ActiveSheet.Columns("A:A").ColumnWidth = 1.5
ActiveSheet.Columns("B:C").ColumnWidth = 16
ActiveSheet.Columns("D:O").ColumnWidth = 10
ActiveSheet.Columns("D:O").NumberFormat = "_(* #,##0_);_(* (#,##0);_(*
""-""_);_(@_)"
ActiveSheet.Rows("1:9").NumberFormat = "General"
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.4)
.RightMargin = Application.InchesToPoints(0.4)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
'.PrintQuality = -3
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 80
'.PrintErrors = xlPrintErrorsDisplayed
End With
Application.ScreenUpdating = True 'Always good to turn on what we turn off
End Sub



"Brite" wrote:
Hi,


I was wondering if there is a better way of running the following code
because as it is, it is really slowing up the macro i am creating. I will
need to run this code on approximately 20 sheets, but not all the sheets are
the same so i can't just select all the sheets at the same time and do it
that way. So the following set of code gets run whenever one of the 20 sheets
gets created.


Does anyone have any pointers?


thanks in advance!


Worksheets(1).Cells.Font.Name = "Arial Narrow"
Worksheets(1).Columns("A:A").ColumnWidth = 1.5
Worksheets(1).Columns("B:C").ColumnWidth = 16
Worksheets(1).Columns("D:O").ColumnWidth = 10
Worksheets(1).Columns("D:O").NumberFormat = "_(* #,##0_);_(* (#,##0);_(*
""-""_);_(@_)"
Worksheets(1).Rows("1:9").NumberFormat = "General"
With Worksheets(1).PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.4)
.RightMargin = Application.InchesToPoints(0.4)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
'.PrintQuality = -3
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 80
'.PrintErrors = xlPrintErrorsDisplayed
End With- Hide quoted text -


- Show quoted text -



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to Speed Up A Code LostInNY Excel Worksheet Functions 2 July 20th 09 06:18 PM
Ned to speed up my code [email protected] Excel Programming 4 June 14th 06 06:11 PM
Speed up Code? Sige Excel Programming 4 July 27th 05 06:21 PM
Speed up code Derick Hughes Excel Programming 0 February 8th 05 04:18 PM
Code Speed Up lists[_2_] Excel Programming 3 August 10th 04 12:06 PM


All times are GMT +1. The time now is 04:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"