Sub Main
'Create Grapher as an Object
Dim Grapher As Object
'Start Grapher
Set Grapher = CreateObject("Grapher.Application")
'Make Grapher visible
Grapher.Visible = True
'Use existing document window
Set plot = Grapher.Documents.Active
'Refer to graph and plot
Set Graph1 = plot.Shapes.Item(1)
Set LineScatterPlot1 = Graph1.Plots.Item(1)
'Calculate Reduced Major Axis fit
'Open line/scatter plot's worksheet
Set Wks = Grapher.Documents.Open(LineScatterPlot1.worksheet)
'RMASlope = (LSFit Slope)/(r value) = Sy/Sx = Standard Deviation of y/Standard Deviation of x
XStandDev = Wks.Columns(LineScatterPlot1.xCol).Statistics.StandardDeviation
YStandDev = Wks.Columns(LineScatterPlot1.yCol).Statistics.StandardDeviation
RMASlope = YStandDev/XStandDev
'RMAIntercept = YBar-RMASlope*XBar
'YBar = Y average, XBar = X average
XBar = Wks.Columns(LineScatterPlot1.xCol).Statistics.Mean
YBar = Wks.Columns(LineScatterPlot1.yCol).Statistics.Mean
RMAIntercept = YBar - RMASlope*XBar
'Get Min and Max X values for plotting fit curve
XMin = Wks.Columns(LineScatterPlot1.xCol).Statistics.Minimum
XMax = Wks.Columns(LineScatterPlot1.xCol).Statistics.Maximum
'Close worksheet
Wks.Close(grfSaveChangesNo)
'RMA Equation = Y = RMASlope*X+RMAIntercept
'Add function plot with this equation
Graph1.AddFunctionPlot(False,"X*"+RMASlope+"+"+RMAIntercept, ,XMin,XMax,,,"RMA Fit")
End Sub