Example Code in the Chart Sheets Code Module

Option Explicit

Dim bPause As Boolean

Sub ScrollChartTypes()

Dim iType As Integer, sName As String Dim fr As Integer fr = FreeFile

Open ThisWorkbook.Path & _

"\charttypes.txt" For Input As #fr

Do While Not EOF(fr)

Input #fr, iType, sName

On Error Resume Next

ActiveChart.ChartType = iType ActiveChart.HasTitle = True ActiveChart.ChartTitle.Text = _ iType & " — " & sName

Delay 2

If bPause Then Do

DoEvents Loop Until bPause = False End If Loop

Close fr End Sub

Sub Delay(rTime As Single) 'Delay rTime seconds (min=.01, max=300) Dim OldTime As Variant 'Safty net

If rTime < 0.01 Or rTime > 300 Then rTime = 1 OldTime = Timer Do

DoEvents

Loop Until Timer - OldTime >= rTime End Sub i_____

Private Sub Chart MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long) If Button = xlPrimaryButton Then bPause = Not bPause End Sub

This code contains three procedures. The main procedure is ScrollChartTypes, which sets the chart type and adjusts the chart's title accordingly. The procedure uses a text file, ChartTypes.txt, that contains a list of all chart types and their names. The contents of that text file are shown in Example 21-4. This file will need to be in the same directory as the workbook.

0 0

Post a comment