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
' This script asks for the Fiscal Year, then defines the macro !fy which gives the Fiscal Year.
' It then calls a syntax file.
' Usage:
' Change the script to refer to the path and sps file name
' Change the minimum and max allowed fiscal year
' The syntax file must be adjusted to use !fy whenever fiscal year is required
' For instance the following syntax works:
' * report.sps.

'DATA LIST LIST /a.
'Begin DATA
'1
'End DATA.
'LIST.

'COMPUTE Year=!fy.
'LIST.

' http://pages.infinit.net/rlevesqu/SampleScripts.htm
' Raynald Levesque 2002/11/08

Option Explicit

Sub Main()
Dim objSyntaxDoc As ISpssSyntaxDoc
Dim strFY As String
Dim CmdStr As String

	On Error GoTo Oopps
	Do					'Last number in InputBox is the default value
	strFY = InputBox$("Must be an integer between 1980 and 2002","Enter the Fiscal Year:","2001")
	Loop Until CInt(strFY)>1980 And CInt(strFY)<2002

	'Define a macro then run it
	CmdStr = "DEFINE !fy()" & strFY & "!ENDDEFINE." & vbCr
	objSpssApp.ExecuteCommands CmdStr,True

	'Open syntax file and run it
	Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("c:\\temp\\report.sps")
	objSyntaxDoc.Visible=True
	objSyntaxDoc.Run
	objSyntaxDoc.Close
	Set objSyntaxDoc = Nothing
	Exit Sub

Oopps:
	MsgBox "Following error occured: " & Err.Description
End Sub