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
50
51
52
53
54
55
56
57
58
'Begin Description
' Print all spo files meeting a "path\\filemask"

' This script processes all files meeting a given mask, eg "*.spo", "out*.spo"
' and located in a given folder 
' Say first 2 files are named output1.spo and myoutput.spo
' then output1.spo is opened and printed
' then myoutput.spo opened and printed.
'End Description

' Code by rlevesque@videotron.ca 2002/08/01
' http://pages.infinit.net/rlevesqu/index.htm

Option Explicit


Sub Main
	Dim objDocuments As ISpssDocuments
	Dim objOutputDoc As ISpssOutputDoc

	Dim strPath As String
	Dim strFileMask As String
	Dim strFname As String
	Dim intCount As Integer
	Dim I As Integer
	
	'define file path and mask	
	strPath		="c:\\temp\\"
	strFileMask	="*.spo"

	'Get the first output file name
	strFname = Dir$(strPath & strFileMask)
	Set objDocuments = objSpssApp.Documents

    While strFname <> ""
		Debug.Print strFname
		' Open the Output, make it visible, select all Pivot Tables:
		Set objOutputDoc = objSpssApp.OpenOutputDoc(strPath & strFname)
		objOutputDoc.Visible = True
'		objOutputDoc.PrintDoc

		' To conserve memory, close all but the designated output document 
		'(using a simple "objOutputDoc.Close" crashes spsswin.exe!)
		intCount = objDocuments.OutputDocCount
		If intCount > 1 Then
		For I = intCount - 1 To 0 Step -1
			Set objOutputDoc = objDocuments.GetOutputDoc(I)
			If Not objOutputDoc.Designated Then
				objOutputDoc.Close
			End If
		Next
		End If
		'Get next output file name
		strFname = Dir$()
    Wend 

	Set objOutputDoc = Nothing
End Sub