Follow

How can I create a graph from one sheet of a file and add 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 and unzip this file: multiple sheet.zip.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\Grapher 12\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. Either copy the script from below and press Ctrl+V to paste it into Scripter, or click File | Open, select the BAS file from the unzipped file you downloaded, and click Open.
  6. Click Script | Run to run the script.
     

*********

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("C:\Program Files\Golden Software\Grapher 7\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("C:\Program Files\Golden Software\Grapher 7\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("C:\Program Files\Golden Software\Grapher 7\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 28, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.