1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
' Script to export data file to a free format ASCII file.
' Raynald Levesque 2003/03/31
' Visit my SPSS site: http://pages.infinit.net/rlevesqu/index.htm

Option Explicit

Sub Main
	Dim objDocuments As ISpssDocuments
    Dim objDataDoc As ISpssDataDoc
	Dim objSPSSInfo As ISpssInfo
	Dim strCmd As String
	Dim strOut As Variant
	Dim lngNOC As Long
	Dim intCnt As Integer
	Dim intVar As Integer
    Dim SpssTextData As Variant
	Dim numVars As Long

	On Error GoTo Oopps
	'Enter path of your file in next line
	strCmd = "GET FILE='c:\\test\\Employee data test.sav'."
	objSpssApp.ExecuteCommands strCmd , True
	Set objSPSSInfo = objSpssApp.SpssInfo
	numVars=objSPSSInfo.NumVariables-1

    Set objDocuments=objSpssApp.Documents
    Set objDataDoc = objDocuments.GetDataDoc(0)
	lngNOC = objDataDoc.GetNumberOfCases
	' Enter name of output file in next line
	Open "c:\\temp\\free format.txt" For Output As #1

    SpssTextData = objDataDoc.GetTextData (objSPSSInfo.VariableAt(0), objSPSSInfo.VariableAt(numVars), 1, lngNOC)
	For intCnt =0 To lngNOC - 1
		For intVar=0 To numVars
		strOut=strOut & " " & SpssTextData(intVar,intCnt)
		Debug.Print strOut
		Next
		Print #1, strOut
		strOut=""
	Next
	Close #1
	Exit Sub

Oopps:
	Debug.Print Err & " " & Err.Description
	Resume Next
End Sub