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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'Begin Description
'This script will cycle through the output items
'of the currently open SPSS output
'For each IGraph found, the script will change the background color to
'a specified color such as yellow
'End Description

'Resolution number: 41963  Created On: Mar 4 2004
'Product Family: SPSS   Version:
'Problem Subject:  Script To change the background color For Each IGraph found In Output file
'Problem Description:  I am using SPSS For Windows. I have an SPSS Output file that contains
'both Pivot Tables And IGraphs. For Each IGraph, I would Like To change the background color.
'How can I Do so automatically?
'Resolution Subject: The following script should assist you.
'Resolution Description:
'The following script should assist you. Highlight the script below And click Edit->Copy. Next,
'click File->New->Script. Click Cancel. Delete Any visible Text. Click Edit->Paste. Next,
'click File->Save As And save the script using a Name such As, 'ChangeBackgroundColor.sbs'.
'Exit the script window.
'In the Output window, make sure you at least have one IGraph. Click Utilities->Run Script.
'Locate the saved script. Click Run. You should notice that For Each IGraph, the background
'color has changed To yellow.
'Read through the script On how To modify it To change the background color of existing
'IGraphs To your desired color.

'Note by Ray: for color codes, you may also use predefined constants vbYellow, vbBlack, vbGreen etc

Option Explicit

Sub Main
	Dim objOutputDoc As ISpssOutputDoc
	Dim objOutputItems As ISpssItems
	Dim objOutputItem As ISpssItem
	Dim objSPSSIGraph As ISpssIGraph
	Dim objIgraph As ISpssIGraph

	Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc

	'We get Output Items and loop through to find each IGraph

	Set objOutputItems = objOutputDoc.Items()
	Dim intItemCount As Integer
		For intItemCount = 0 To objOutputItems.Count - 1
		Set objOutputItem = objOutputItems.GetItem(intItemCount)
				If objOutputItem.SPSSType = SPSSIGraph Then
					Set objIgraph = objOutputItem.Activate
					Set objIgraph = objOutputItem.GetIGraphOleObject
					Call ChangeBackgroundColor (objIgraph)
					objOutputItem.Deactivate
				End If
		Next
End Sub

Sub ChangeBackgroundColor (objIgraph As ISpssIGraph)
	Dim MyDataRegion As ISpssIGraphDataRegion
	Set MyDataRegion = objIgraph.GetDataRegion
	With objIgraph.GetDataRegion
		'here we change the background color to yellow
		'use the chart below to replace the code
		'values for a different color
		.GetArea.BackgroundColor = RGB(255,255,0)
		'Color code below
		'RGB values follow the color name
		'Black 0, 0, 0
		'Blue 0, 0, 255
		'Cyan 0, 255, 255
		'Green 0, 255, 0
		'Magenta 255, 0, 255
		'Red 255, 0, 0
		'White 255, 255, 255
		'Yellow 255, 255, 0
	End With

	'Always redraw to keep the changes
	objIgraph.Redraw
End Sub