Change folder of analysis - Statistica Visual Basic - Statistica - Dell Community

Change folder of analysis

Change folder of analysis

This question is not answered

 Hello,

I am trying to do the following (using a macro)

Run an analysis, say a one-way ANOVA, and put it in a folder whose name and location I specified.

The issue is that, following this page's instructions (documentation.statsoft.com/STATISTICAHelp.aspx)  I figured out how to do this, but every object I put in gets named either "Spreadsheet" or "Graph", and they ARE different objects (if possible, I would like to retain the default name statistica gives). Please help! Any suggestions or advice is greatly appreciated.

Regards, 

M

 

 

All Replies
  •  I took a recorded macro that makes ANOVA output and added these lines to access the output spreadsheet as a spreadsheet:


        Dim ANOVAOutput As Spreadsheet
        Set ANOVAOutput = oStaDocs2.Item(1)

    then took from an example in help, the following lines, modified slightly:

    Dim WB As Workbook
    'Create a Workbook item which will represent
    'each type of document while they are being
    'inserted into the workbook
    Dim NewItem As WorkbookItem
    'Create a folder for each document type
    Dim SpreadsheetFolder As WorkbookItem
    Set WB = Application.Workbooks.New
    Set SpreadsheetFolder = WB.InsertFolder _
    (WB.Root,scWorkbookFirstChild)
    SpreadsheetFolder.Name = "Output"
    Set NewItem = WB.InsertObject _
    (ANOVAOutput,SpreadsheetFolder,)

    WB.Visible=True

    and added this line:

    NewItem.Name = Mid(ANOVAOutput.Header, 1, 20)

    to name the spreadsheet with the first 20 characters from the header. you could leave out the "Mid" statement and use the whole header, but that can make for some pretty long names.

    Hopefully that is helpful. I will post my whole macro below.

  • Sub Main

        Dim S1 As Spreadsheet
        Set S1 = Spreadsheets.Open ("C:\Program Files\StatSoft\STATISTICA 10\Examples\Datasets\Adstudy.sta")
        S1.Visible = True

        Dim newanalysis2 As Analysis
        Set newanalysis2 = Analysis (scGLM, S1)
        Dim oStaDocs2 As StaDocuments

        Dim oAD1 As STAGLM.GLMStartup
        Set oAD1 = newanalysis2.Dialog
        newanalysis2.Run

        Dim oAD2 As STAGLM.GLMSpecifications
        Set oAD2 = newanalysis2.Dialog
        oAD2.AnalysisSyntax = "GLM;" + vbCrLf + _
            "   DEPENDENT = ""MEASURE01"";" + vbCrLf + _
            "   GROUPS = ADVERT(1 2);" + vbCrLf + _
            "   COVARIATE = none;" + vbCrLf + _
            "   DESIGN =  ADVERT;" + vbCrLf + _
            "   INTERCEPT = include;" + vbCrLf + _
            "LACKOFFIT = no;" + vbCrLf + _
            "   PARAM = sigma;" + vbCrLf + _
            "   SSTYPE = 6;" + vbCrLf + _
            "   ESTIMATE = none;" + vbCrLf + _
            "   SDELTA = 7;" + vbCrLf + _
            "   IDELTA = 12;" + vbCrLf + _
            "   RANDOM = none;" + vbCrLf + _
            "   SURFACE = none;" + vbCrLf + _
            "   MIXTURE = none;" + vbCrLf + _
            "   REPEATED = none;" + vbCrLf + _
            "   WDESIGN = none;" + vbCrLf + _
            "   SAMPLE = none;" + vbCrLf + _
            "   OUTPUT = none;" + vbCrLf + _
            ""

        newanalysis2.Run

        Dim oAD3 As STAGLM.GLMResults
        Set oAD3 = newanalysis2.Dialog
        oAD3.PlotRelativeVariancesOfTotal = False
        oAD3.Pillai = False
        oAD3.Hotelling = False
        oAD3.Roy = False
        oAD3.PForConfidenceLimits = 0.95
        oAD3.PLevelForHighlighting = 0.05
        oAD3.EffectForMeanComparisons = "ADVERT"
        oAD3.EnterContrastsSeparatelyForEachFactor = True
        oAD3.ContrastCoefficients = "ADVERT ( 1 1 )  "
        oAD3.PillaiTestForPlannedComparison = False
        oAD3.HotellingTestForPlannedComparison = False
        oAD3.RoyTestForPlannedComparison = False
        oAD3.EffectForMarginalMeans = "ADVERT"
        oAD3.ShowStandardErrors = True
        oAD3.DisplayStandardErrorOfMean = False
        oAD3.DependentVariablesForResiduals = "3"
        oAD3.ComputeExtendedResidualStatistics = False
        oAD3.SortCasesBy = scGlmCaseNumbers
        oAD3.PlotAbsoluteValues = True
        oAD3.ValuesForY = "Non"
        oAD3.ShowIntercept = False
        oAD3.NumberOfDigitsForPredictionEquation = 10
        oAD3.VariablesForDesirabilityProfiler = "3"
        oAD3.SetFactorsAtMean = True
        oAD3.FactorGridSpecifications = "ADVERT 1 2 1"
        oAD3.ShowDesirabilityFunction = True
        oAD3.LowFactorValues = "1.16627 "
        oAD3.DesirabilityLowFactorValues = "0 "
        oAD3.MediumFactorValues = "5.9 "
        oAD3.DesirabilityMediumFactorValues = "0.5 "
        oAD3.HighFactorValues = "10.6337 "
        oAD3.DesirabilityHighFactorValues = "1 "
        oAD3.CurvatureParametersS = "1 "
        oAD3.CurvatureParametersT = "1 "

        Dim oAD4 As STAGLM.GLMDesirabilityOptions
        Set oAD4 = newanalysis2.Dialog.GetOptionsForDesirability
        oAD4.ConfidenceIntervals = True
        oAD4.ShowSpreadsheetsWithPlottedValues = False
        oAD4.LabelConfPredLimitsForPredValues = False
        oAD4.ShowTextValsForFactorSettings = True
        oAD4.FitQuadraticSurface = True
        oAD4.ShowTheGridPoints = False
        oAD4.ShowAreaContours = True

        newanalysis2.Dialog.SetOptionsForDesirability oAD4
        Set oAD4 = Nothing

        Set oStaDocs2 = oAD3.TestOfAllEffects
        Set AO = newanalysis2.RouteOutput(oStaDocs2)
        AO.Visible = True
        If AO.HasWorkbook Then
            Set AWB = AO.Workbook
        Else
            Set AWB = Nothing
        End If

        Dim ANOVAOutput As Spreadsheet
        Set ANOVAOutput = oStaDocs2.Item(1)


        Set oStaDocs2 = Nothing

    Dim WB As Workbook
    'Create a Workbook item which will represent
    'each type of document while they are being
    'inserted into the workbook
    Dim NewItem As WorkbookItem
    'Create a folder for each document type
    Dim SpreadsheetFolder As WorkbookItem
    Set WB = Application.Workbooks.New
    Set SpreadsheetFolder = WB.InsertFolder _
    (WB.Root,scWorkbookFirstChild)
    SpreadsheetFolder.Name = "Output"
    Set NewItem = WB.InsertObject _
    (ANOVAOutput,SpreadsheetFolder,)
    NewItem.Name = Mid(ANOVAOutput.Header, 1, 20)

    WB.Visible=True


    End Sub