This article contains a sample script for creating a graph from a multiple sheet XLS file and adding a new curve from a different sheet in the same XLS file.
To run this script:
- Click here to download the BAS file: multiple sheet.zip.
- Extract the files and move the Excel worksheet to the Grapher samples directory.
- Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- Click the Start/Resume icon (
) in the Script Manager.
Sub Main 'Create Grapher as an Object Dim Grapher As Object 'Start Grapher Set Grapher = CreateObject("Grapher.Application") Grapher.Visible = True 'Create a new document window Set Plot1 = Grapher.Documents.Add(grfPlotDoc) 'Create line plot graph Plot1.Shapes.AddLinePlotGraph(Grapher.Path + "\Samples\multiple sheet.xls!Sheet1",1,2) 'Define object pointer Set Graph1 = Plot1.Shapes.Item(1) 'Define object pointer Set LineScatterPlot1 = Graph1.Plots.Item(1) 'Select object LineScatterPlot1.Select 'Add line plot to graph Graph1.AddLinePlot(Grapher.Path + "\Samples\multiple sheet.xls!Sheet2",1,2,"X Axis 1","Y Axis 1") 'DeselectAll selected objects Plot1.Selection.DeselectAll 'Define object pointer Set LineScatterPlot2 = Graph1.Plots.Item(2) 'Select object LineScatterPlot2.Select 'Add line plot to graph Graph1.AddLinePlot(Grapher.Path + "\Samples\multiple sheet.xls!Sheet3",1,2,"X Axis 1","Y Axis 1") 'DeselectAll selected objects Plot1.Selection.DeselectAll 'Define object pointer Set LineScatterPlot3 = Graph1.Plots.Item(3) 'Select object LineScatterPlot3.Select End Sub
Updated October 12, 2018