Microsoft Office Tutorials and References
In Depth Information
Sizing and Aligning ChartObjects
The following macro performs the same operation as the preceding FormatAllCharts
procedure but works on all the chart sheets in the active workbook:
Sub FormatAllCharts2()
Dim cht as Chart
For Each cht In ActiveWorkbook.Charts
With cht
.ChartType = xlLineMarkers
.ApplyLayout 3
.ChartStyle = 12
.ClearToMatchStyle
.SetElement msoElementChartTitleAboveChart
.SetElement msoElementLegendNone
.SetElement msoElementPrimaryValueAxisTitleNone
.SetElement msoElementPrimaryCategoryAxisTitleNone
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 1000
End With
Next cht
End Sub
Sizing and Aligning ChartObjects
A ChartObject object has standard positional ( Top and Left ) and sizing ( Width and
Height ) properties that you can access with your VBA code. The Excel Ribbon has controls (in
the Chart Tools Format Size group) to set the Height and Width , but not the Top and Left .
The following example resizes all ChartObject objects on a sheet so that they match the
dimensions of the active chart. It also arranges the ChartObject objects into a user-specified
number of columns.
Sub SizeAndAlignCharts()
Dim W As Long, H As Long
Dim TopPosition As Long, LeftPosition As Long
Dim ChtObj As ChartObject
Dim i As Long, NumCols As Long
If ActiveChart Is Nothing Then
MsgBox “Select a chart to be used as the base for the sizing”
 
Search JabSto ::




Custom Search