Create a graph from one sheet and add a curve from another sheet in that same file using Grapher automation

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:

 

  1. Download the attached multiple_sheet.xls and put it in Grapher's Samples directory.
  2. Copy the script below.
  3. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  4. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  5. Press Ctrl+V to paste it into the Script Manager.
  6. Click the green arrow Start/Resume icon in the Script Manager.
     

Sub Main

'Initialize Grapher
Dim Grapher As Object
Set Grapher = CreateObject("Grapher.Application")
Grapher.Visible = True
Set Plot1 = Grapher.Documents.Add(grfPlotDoc)

'Create line plot graph
Plot1.Shapes.AddLinePlotGraph(Grapher.Path + "\Samples\multiple sheet.xls!Sheet1",1,2)
Set Graph1 = Plot1.Shapes.Item(1)
Set LineScatterPlot1 = Graph1.Plots.Item(1)

'Add line plot to graph
Graph1.AddLinePlot(Grapher.Path + "\Samples\multiple sheet.xls!Sheet2",1,2,"X Axis 1","Y Axis 1")
Set LineScatterPlot2 = Graph1.Plots.Item(2)

'Add line plot to graph
Graph1.AddLinePlot(Grapher.Path + "\Samples\multiple sheet.xls!Sheet3",1,2,"X Axis 1","Y Axis 1")
Set LineScatterPlot3 = Graph1.Plots.Item(3)

End Sub

 

Updated August 13, 2019

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.