Microsoft Office Tutorials and References
In Depth Information
Exporting Charts as GIF Files
Dim Ser As Series
Dim i As Long
On Error Resume Next
Set RngLabels = Application.InputBox _
(prompt:=”First cell for data labels?”, Type:=8)
If RngLabels Is Nothing Then Exit Sub ‘Canceled
Set RngLabels = RngLabels(1)
On Error GoTo 0
Set Ser = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
Ser.HasDataLabels = True
Counter = 0
For Each Pt In Ser.Points
Pt.DataLabel.Text = RngLabels.Offset(Counter, 0)
Counter = Counter + 1
Next Pt
End Sub
The JWalk Chart Tools add-in, available on the companion CD-ROM,
includes a utility to apply data labels to the active chart.
Exporting Charts as GIF Files
Saving a chart as a GIF file is very easy: Just use the Export method of the Chart
object. Here’s a simple macro that saves the active chart as a GIF file named
mychart.gif:
Sub ExportToGIF()
If ActiveChart Is Nothing Then
MsgBox “Select a chart.”
Else
ActiveChart.Export “mychart.gif”, “GIF”
End If
End Sub
The macro first checks to ensure that a chart is active. If so, it saves the chart to
the current directory.
If you prefer to be prompted for a filename and location, use the macro that
follows. This macro uses the GetSaveAsFilename function to display a dialog box
with a default filename (the chart’s name) and directory. The user can then accept
these defaults or select a different directory or filename. Figure 16-13 shows the
Search JabSto ::




Custom Search