L
lance-news
I am setting oAPP in SUB OPENFILE. How do I pass oAPP
to the SUB RunANOVA?
I am using
oAPP.ExecuteCommands sANOVA, True
in Sub RunANOVA but I keep getting
an error and I assume it is because
oAPP is not getting passed to
SubANOVA
Lance
Sub Openfile()
Dim Varlist As String
'OPEN DIALOG BOX TO OPEN SPSSFILE
OFile = Application.GetOpenFilename("SPSS Datafile, *.sav")
'USE OLE TO OPEN SPSS
Set oAPP = CreateObject("SPSS.Application")
Set oDoc = oAPP.OpenDataDoc(OFile)
'oDoc.Visible = True
'USE OLE TO OPEN OUTPUT DOC
Set oOut = oAPP.NewOutputDoc
'Switch back to Excel after SPSS opens
AppActivate "Microsoft Excel"
End Sub
Sub RunANOVA()
Worksheets("Vars").Select
Range("C2:C101").Select
'Find out how many variables there are in the ANOVA
myCount = Application.CountA(Selection)
'If over 100, then stop (SPSS can only input 100)
If (myCount > 99) Then
MsgBox ("Wait a minute there buddy, SPSS only allows you to input up to
100 variables")
Sheets("Mainsheet").Select
End
End If
'Concantenate variables so that they are not an array
For RowIndex = 2 To (1 + myCount)
myVars4ANOVA = myVars4ANOVA & Cells(RowIndex, 3) & " "
'Add plus sign for Basic Tables
If (RowIndex <> (1 + myCount)) Then
myVars4Table = myVars4Table & Cells(RowIndex, 3) & "+"
Else
myVars4Table = myVars4Table & Cells(RowIndex, 3)
End If
Next RowIndex
'Get grouping variable
Groupvar = Range("E2").Value
sANOVA = "ONEWAY " & myVars4ANOVA & " BY Groupvar /STATISTICS
DESCRIPTIVES HOMOGENEITY /MISSING ANALYSIS /POSTHOC = LSD ALPHA(.05)."
oAPP.ExecuteCommands sANOVA, True
sTables = "* Basic Tables. TEMPORARY. NUMERIC T0000000. LEAVE T0000000.
VARIABLE LABEL T0000000 'Table Total'. VALUE LABELS T0000000 0 ' '.
TABLES /FORMAT BLANK MISSING('.') /OBSERVATION" & myVars4ANOVA & "
/TABLES (" & myVars4Table & "BY (" & Groupvar & "+ T0000000) >
(STATISTICS) /STATISTICS mean( ( F7.2 ))."
oAPP.ExecuteCommands sTables, True
oAPP.CloseDataDoc (OFile)
oOut.CloseOutputDoc (oOut)
End Sub
to the SUB RunANOVA?
I am using
oAPP.ExecuteCommands sANOVA, True
in Sub RunANOVA but I keep getting
an error and I assume it is because
oAPP is not getting passed to
SubANOVA
Lance
Sub Openfile()
Dim Varlist As String
'OPEN DIALOG BOX TO OPEN SPSSFILE
OFile = Application.GetOpenFilename("SPSS Datafile, *.sav")
'USE OLE TO OPEN SPSS
Set oAPP = CreateObject("SPSS.Application")
Set oDoc = oAPP.OpenDataDoc(OFile)
'oDoc.Visible = True
'USE OLE TO OPEN OUTPUT DOC
Set oOut = oAPP.NewOutputDoc
'Switch back to Excel after SPSS opens
AppActivate "Microsoft Excel"
End Sub
Sub RunANOVA()
Worksheets("Vars").Select
Range("C2:C101").Select
'Find out how many variables there are in the ANOVA
myCount = Application.CountA(Selection)
'If over 100, then stop (SPSS can only input 100)
If (myCount > 99) Then
MsgBox ("Wait a minute there buddy, SPSS only allows you to input up to
100 variables")
Sheets("Mainsheet").Select
End
End If
'Concantenate variables so that they are not an array
For RowIndex = 2 To (1 + myCount)
myVars4ANOVA = myVars4ANOVA & Cells(RowIndex, 3) & " "
'Add plus sign for Basic Tables
If (RowIndex <> (1 + myCount)) Then
myVars4Table = myVars4Table & Cells(RowIndex, 3) & "+"
Else
myVars4Table = myVars4Table & Cells(RowIndex, 3)
End If
Next RowIndex
'Get grouping variable
Groupvar = Range("E2").Value
sANOVA = "ONEWAY " & myVars4ANOVA & " BY Groupvar /STATISTICS
DESCRIPTIVES HOMOGENEITY /MISSING ANALYSIS /POSTHOC = LSD ALPHA(.05)."
oAPP.ExecuteCommands sANOVA, True
sTables = "* Basic Tables. TEMPORARY. NUMERIC T0000000. LEAVE T0000000.
VARIABLE LABEL T0000000 'Table Total'. VALUE LABELS T0000000 0 ' '.
TABLES /FORMAT BLANK MISSING('.') /OBSERVATION" & myVars4ANOVA & "
/TABLES (" & myVars4Table & "BY (" & Groupvar & "+ T0000000) >
(STATISTICS) /STATISTICS mean( ( F7.2 ))."
oAPP.ExecuteCommands sTables, True
oAPP.CloseDataDoc (OFile)
oOut.CloseOutputDoc (oOut)
End Sub