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
48
49
'begin description
'Purpose: create a macro call for each value label of a given variable.
'Requirement: 	must have data in data editor
'				folder c:\\temp\\ is assumed to exist
' In this example the macro needs to be called once for each value label of variable "mdotco"
' The macro is named !macro and it requires 2 parameters:
'    cty  = the value
'    name = the value label.
'end description

'Written by Raynald Levesque on 2004/06/03
'SPSS site: http://pages.infinit.net/rlevesqu/index.htm

Const cVARNAME As String ="mdotco"
Option Explicit


Sub Main
	' Declare variables and get the SpssInfo object:
	Dim objSpssInfo As ISpssInfo
	Dim i As Integer, j As Integer
	Dim lngLength As Long
	Set objSpssInfo = objSpssApp.SpssInfo
	Open "C:\\temp\\macro calls.sps" For Output As #1

	Dim ValCount As Integer
	With objSpssInfo
		For i = 0 To .NumVariables - 1
			If .VariableAt(i) = cVARNAME Then
				' Get the values and value labels
				ValCount = .NumberOfValueLabels(i)
				If ValCount > 0 Then
					If  .VarType(i) = SpssDataString Then
						For j = 0 To ValCount - 1
							Print #1,"!macro cty='" & .ValueAt(i, j) & "'  name='" & .ValueLabelAt (i, j) & "'."
						Next
						Else
						For j = 0 To ValCount-1
							Print #1,"!macro cty=" & .ValueAt(i, j) & " name='" & .ValueLabelAt (i, j) & "'."
						Next
					End If
				End If
			End If
		Next i
	End With
	Close #1
	objSpssApp.ExecuteInclude ("c:\\temp\\macro calls.sps",False)
	Set objSpssInfo = Nothing
End Sub