User Guide
639
SPSS Scripting
Facility
Getting SPSS Automation Objects (Scripting)
To get an object means to create a reference to the object so that you can use
properties and methods to do something. Each object reference that you get is stored
in a variable. To get an object, first declare an object variable of the appropriate
class, then set the variable to the specific object. For example, to get the designated
output document:
Dim objOutputDoc As ISpssOutputDoc
Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc
you use properties and methods of objects higher in the object hierarchy to get at the
objects beneath. The second statement above gets the designated output document
using
GetDesignatedOutputDoc, a method associated with the application object,
which is the highest-level object. Similarly, to get a pivot table object, you first get
the output document that contains the pivot table, and then get the collection of
items in that output document, and so on.
Example: Getting an Output Object
This script gets the third output item in the designated output document and activates
it. If that item is not an OLE object, the script produces an error.
Sub Main
Dim objOutputDoc As ISpssOutputDoc'declare object variables
Dim objOutputItems As ISpssItems
Dim objOutputItem As ISpssItem
Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc'get reference to designated output doc
Set objOutputItems = objOutputDoc.Items() 'get collection of items in doc
Set objOutputItem = objOutputItems.GetItem(2) 'get third output item
'(item num bers start at 0 so " 2" gets third)
objOutputItem.Activate 'activate output item
End sub