Hello All,
I am in the process of having to move from Excel 2003 to Excel 2007. I have one macro that format a chart page (XY Scatter) with headers, footers, chart area, and various plot attributes. In Excel 2003 the macro takes about 2 seconds. In Excel 2007 this macro takes more than 30 seconds. Since I generate many graphs this is unacceptable. In both version, the default printer is set for Adobe PDF so Excel does not have to access the remote spooler. We (I have a colleague who has helped) have gotten it down to 15 seconds by simulating an enter key, but sometimes that fails and I have to manually enter Okay. (This is currently commented out of the code).
Attached is the code (sorry it is so long). But I am looking for any help anyone can give me.
Also, I can not make this the default chart type since I have other colleagues who use it.
Thanks for you time and help.
Mike Virostko
I am in the process of having to move from Excel 2003 to Excel 2007. I have one macro that format a chart page (XY Scatter) with headers, footers, chart area, and various plot attributes. In Excel 2003 the macro takes about 2 seconds. In Excel 2007 this macro takes more than 30 seconds. Since I generate many graphs this is unacceptable. In both version, the default printer is set for Adobe PDF so Excel does not have to access the remote spooler. We (I have a colleague who has helped) have gotten it down to 15 seconds by simulating an enter key, but sometimes that fails and I have to manually enter Okay. (This is currently commented out of the code).
Attached is the code (sorry it is so long). But I am looking for any help anyone can give me.
Also, I can not make this the default chart type since I have other colleagues who use it.
Thanks for you time and help.
Mike Virostko
Code:
Sub RF_Chart_page()
'
' Reformat_Chart_page Macro
' Macro recorded by Michael J. Virostko
'
' Keyboard Shortcut: Ctrl+o
'
' Set up Overall Page size along with the Header and Footers
'
'Arg1 Header dialog
'Arg2 Footer dialog
'Arg3 left margin
'Arg4 Right margin
'Arg5 Top Margin
'Arg6 Bottom Margin
'Arg7 printed chart size
'Arg8
'Arg9
'Arg10 Page orientation 1= portrate 2= Landscape
'Arg11 paper setting xlPaperLetter
'Arg12 Scaling
'Arg13 First Page
'Arg14 Black and white
'Arg15 Pring Quality
'Arg16 Head margin
'Arg17 foot margin
'Aeg18 Draft quality
ActiveWindow.Zoom = 100
ActiveChart.Activate
' Print Page Setup
'Application.SendKeys "{ENTER}", False
'Application.Dialogs(xlDialogPageSetup).Show _
' Arg2:="&L&""Times New Roman,Bold""My Corporation" & Chr(10) & "&""Times New Roman,Regular""&8&F - &A" & _
' "&R&""Times New Roman,Bold""&10Page &P" & Chr(10) & "Printed " & "&D", _
' Arg3:=0.25, _
' Arg4:=0.25, _
' Arg5:=0.25, _
' Arg6:=0.75, _
' Arg16:=0.5, _
' Arg17:=0.5, _
' Arg10:=2, _
' Arg11:=xlPaperLetter, _
' Arg12:=100, _
' Arg14:=False, _
' Arg15:=600
'
With ActiveChart.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = _
"&""Times New Roman,Bold""My Corporation" & Chr(10) & "&""Times New Roman,Regular""&8&F - &A"
.CenterFooter = ""
' .RightFooter = "&10Page &P" & Chr(10) & "Printed " & "&D"
.RightFooter = "&""Times New Roman,Bold""&10Page &P" & Chr(10) & "Printed " & "&D"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.ChartSize = xlFullPage
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.BlackAndWhite = False
.Zoom = 100
End With
'For Excel 2007, Need to define the Chart Area
'
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Top = 0
ActiveChart.ChartArea.Left = 0
ActiveChart.ChartArea.Width = 747 '735
ActiveChart.ChartArea.Height = 532 '530
ActiveChart.Deselect
'
' Define the area for the plot, needed only for Excel 2003
'
If 1 = 1 Then
ActiveChart.PlotArea.Select
Selection.Left = 25
Selection.Width = 695
Selection.Top = 50
Selection.Height = 450
End If
'
' Define the Chart area (no border)
'
ActiveChart.ChartArea.Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
Selection.Shadow = False
Selection.Interior.ColorIndex = xlNone
'
' Set up graph to have only major gridlines
'
ActiveChart.PlotArea.Select
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
'
' Set up major gridlines to be a dashed line
'
ActiveChart.Axes(xlCategory).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 57
.Weight = xlHairline
.LineStyle = xlDot
End With
'
' xlCategory represents x
' xlvalue represents y
'
' Format the y-axis
'
ActiveChart.Axes(xlValue).AxisTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
' .MinimumScale = 11.4
' .MaximumScale = 14.9
' .MinorUnit = 0.05
' .MajorUnit = 0.5
.Crosses = xlCustom
.CrossesAt = -200
' .ReversePlotOrder = False
' .ScaleType = xlLinear
' .DisplayUnit = xlNone
End With
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlCross
.MinorTickMark = xlInside
.TickLabelPosition = xlNextToAxis
End With
Selection.TickLabels.AutoScaleFont = True
With Selection.TickLabels.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
Selection.TickLabels.NumberFormat = "0"
' Selection.TickLabels.NumberFormat = "0.0"
'
' Format the x-axis
'
ActiveChart.Axes(xlCategory).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlAutomatic
End With
With Selection
.MajorTickMark = xlCross
.MinorTickMark = xlInside
.TickLabelPosition = xlLow
' .MinimumScale = 0.6
' .MaximumScale = 1.2
' .MinorUnit = 0.01
' .MajorUnit = 0.05
.Crosses = xlCustom
.CrossesAt = -200
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
Selection.TickLabels.AutoScaleFont = True
With Selection.TickLabels.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
' Selection.TickLabels.NumberFormat = "0.0"
' Selection.TickLabels.NumberFormat = "0.00"
Selection.TickLabels.NumberFormat = "0"
ActiveChart.Axes(xlCategory).AxisTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
'
' Format the plot area for white background, solid border.
'
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone
'
' Format the Chart Title
'
ActiveChart.ChartTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.Deselect
'
' Reformat the various titles
'
ActiveChart.Axes(xlCategory).AxisTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.ReadingOrder = xlContext
.Orientation = xlHorizontal
End With
ActiveChart.Axes(xlValue).AxisTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.ReadingOrder = xlContext
.Orientation = xlUpward
End With
ActiveChart.ChartTitle.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Bold"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.ReadingOrder = xlContext
.Orientation = xlHorizontal
End With
'
' Force Legend to have a border.
'
ActiveChart.Legend.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
' Selection.Interior.ColorIndex = xlNone
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
.Background = xlTransparent
End With
' ActiveChart.Deselect
End Sub