'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