Chart Object and the Charts Collection Example
This example creates a 3D chart from a given range, formats it, and saves a picture of it as a .jpg image:
|
Sub CreateAndExportChart() | |
|
Dim oCht As Chart | |
|
'Create a new (blank) chart | |
|
Set oCht = Charts.Add | |
|
'Format the chart | |
|
With oCht | |
|
.ChartType = xl3DColumnStacked | |
|
'Set the data source and plot by columns | |
|
.SetSourceData Source:=Range("Sheet1!$B$2:$D$8") |
, PlotBy:=xlColumns |
|
'Create a new sheet for the chart | |
|
.Location Where:=xlLocationAsNewSheet | |
|
'Size and shape matches the window it's in | |
|
.SizeWithWindow = True | |
|
'Turn of stretching of chart | |
|
.AutoScaling = False | |
|
'Set up a title | |
|
.HasTitle = True | |
|
.ChartTitle.Caption = "Main Chart" | |
|
'No titles for the axes | |
|
.Axes(xlCategory).HasTitle = False | |
|
.Axes(xlValue).HasTitle = False | |
|
'Set the 3D view of the chart | |
|
.RightAngleAxes = False | |
|
.Elevation = 50 'degrees | |
|
.Perspective = 3 0 'degrees | |
|
.Rotation = 20 'degrees | |
|
.HeightPercent = 100 | |
|
'No data labels should appear | |
|
.ApplyDataLabels Type:=xlDataLabelsShowNone | |
|
'Save a picture of the chart as a jpg image | |
|
.Export "c:\" & .Name & ".jpg", "jpg", False | |
|
End With | |
|
End Sub |
Post a comment