Microsoft Office Tutorials and References
In Depth Information
Sizing and Aligning ChartObjects
Exit Sub
End If
‘Get columns
On Error Resume Next
NumCols = InputBox(“How many columns of charts?”)
If Err.Number <> 0 Then Exit Sub
If NumCols < 1 Then Exit Sub
On Error GoTo 0
‘Get size of active chart
W = ActiveChart.Parent.Width
H = ActiveChart.Parent.Height
‘Change starting positions, if necessary
TopPosition = 100
LeftPosition = 20
For i = 1 To ActiveSheet.ChartObjects.Count
With ActiveSheet.ChartObjects(i)
.Width = W
.Height = H
.Left = LeftPosition + ((i - 1) Mod NumCols) * W
.Top = TopPosition + Int((i - 1) / NumCols) * H
End With
Next i
End Sub
If no chart is active, the user is prompted to activate a chart that will be used as the basis for
sizing the other charts. I use an InputBox function to get the number of columns. The values for
the Left and Top properties are calculated within the loop.
Figure 18-6 shows some charts, neatly sized and arranged.
This workbook, named size and align charts.xlsm , is available on the
companion CD-ROM.
 
Search JabSto ::




Custom Search