Plot Area Object Example

This example uses the PlotArea object to make all the embedded charts in the workbook (not chart sheets) have the same size and position plot area, regardless of the formatting of the axes (for example, different fonts and number scales):

Sub MakeChartAreasSameSizeAsFirst() Dim oCht As Chart, oPA As PlotArea Dim dWidth As Double, dHeight As Double Dim dTop As Double, dLeft As Double

'Get the dimensions of the inside of the plot area of the first chart With ActiveSheet.ChartObjects(1).Chart.PlotArea dWidth = .InsideWidth dHeight = .InsideHeight dLeft = .InsideLeft dTop = .InsideTop End With

'Loop through the charts in the workbook

For Each oCht In Charts 'Get the PlotArea

Set oPA = oCht.PlotArea

'Size and move the plot area With oPA

If .InsideWidth > dWidth Then 'Too big, make it smaller .Width = .Width - (.InsideWidth - dWidth) Else

'Too small, move it left and make bigger .Left = .Left - (dWidth - .InsideWidth) .Width = .Width + (dWidth - .InsideWidth) End If

If .InsideHeight > dHeight Then 'Too big, make it smaller

.Height = .Height - (.InsideHeight - dHeight) Else

'Too small, move it left and make bigger .Top = .Top - (dHeight - .InsideHeight) .Height = .Height + (dHeight - .InsideHeight) End If

'Set the position of the inside of the plot area .Left = .Left + (dLeft - .InsideLeft) .Top = .Top + (dTop - .InsideTop) End With Next End Sub

+1 0

Post a comment