View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jeff Gross Jeff Gross is offline
external usenet poster
 
Posts: 64
Default Plot Area Changes Automatically When Updated

This was the modified code I used from your example - thanks a huge - it
works great!.

Public Sub SetupCharts()
'This code will force all charts to be the same size and format.

On Error GoTo ErrorHandler

Dim mycharts As Chart
Dim Sheettarget As Excel.Worksheet
Dim lcount As Long
Dim lcharts As Long

If Application.ActiveWorkbook Is Nothing Then
MsgBox gszERR_NO_WORKBOOK, vbCritical, gszAPP_TITLE
Exit Sub
End If

'Gather info about the workbook.
Set Sheettarget = Application.ActiveWorkbook.ActiveSheet
lcharts = Sheettarget.ChartObjects.Count
ChartHeight = 325
ChartWidth = 790

'Set size of charts
For lcount = 1 To lcharts
With Sheettarget.Shapes.Range(lcount)
.Height = ChartHeight
.Width = ChartWidth
End With

With Sheettarget.ChartObjects(lcount).Activate
Sheettarget.ChartObjects(lcount).SendToBack
'Sheettarget.Shapes.Range(lcount).Name = "Chart" & lcount

'Chart AREA - OK
ActiveChart.ChartArea.Select
With Selection
.Interior.Pattern = Solid
.Interior.Color = RGB(255, 255, 255)
.Border.LineStyle = Solid
.Border.ColorIndex = 1
End With

'Chart TITLE - OK
ActiveChart.ChartTitle.Select
With Selection
.Font.Size = 12
.Font.ColorIndex = 1
' .Left = 190
.Top = 0
.HorizontalAlignment = xlCenter
.AutoScaleFont = False
.Interior.Color = RGB(255, 255, 255)
End With

'Chart LEGEND - OK
ActiveChart.Legend.Select
With Selection
.AutoScaleFont = False
.Font.Size = 9
.Border.LineStyle = Solid
.Border.Color = 1
.Interior.Pattern = Solid
.Interior.Color = RGB(255, 255, 255)
End With

'Plot AREA - OK
ActiveChart.PlotArea.Select
With Selection
PlotTop = ActiveChart.ChartTitle.Font.Size + 15
Plotheight = ChartHeight - PlotTop - 10
.Top = PlotTop
.Left = 20
.Width = ChartWidth - 60
.Border.LineStyle = Solid
.Border.Color = 1
.Height = Plotheight
ph = ActiveChart.PlotArea.Height
.Interior.Pattern = Solid
.Interior.Color = RGB(192, 192, 192)
End With

'Repaint all changes to chart
ActiveChart.Refresh
End With
Next lcount

Exit Sub

ErrorHandler:
Application.ScreenUpdating = True

msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext

End Sub



Again, thanks a lot.