Date: Sat, 10 Sep 2005 09:37:52 -0400
Reply-To: thennig@idirect.com
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Timothy Hennigar <thennig@idirect.com>
Organization: Timothy Hennigar
Subject: Re: Table number
In-Reply-To: <4322A189.12931.32D5AB3@localhost>
Content-Type: text/plain; charset="us-ascii"
I have written similar - I had a large script that did many things that
I have broken into smaller chunks - this piece essentially opens a
file (txt) and writes a table number and the table title for all PIVOT
tables in the output window .. it also changes the title in the navigator
window and the pivot table title itself (thanks to another on the list)
adding the table number ... and the prompts you to save the output window
... what you want is in here .. this program works flawlessly on <= to say
100 tables - but on large files (more than that) its unstable (bells start
ringing, SPSS loses its memory of current directory, etc) but it still seems
to work - why the problem on large files - have no idea - its obviously
memory related .. you don't need all of this .. but creating a table number
system is here if you can understand the code - didn't want to take the time
to pull out only that code ... hopefully you can see what you need ..
Option Explicit
'
Sub MAIN
'
' RUNS ON SINGLE TABLE OUTPUT FILE CALLED BY SYNTAX AT END OF TABLE RUN
' Modified Date: January 31, 2005
'
' Objectives:
' Create tables of contents
' Select visible output, set page breaks, remove unwanted output
' Save output to file with same name as open syntax window
' Change Pivot Table characteristics
'DECLARATIONS
Dim objSpssApp As Object 'SPSS Application
Dim objSpssOpt As ISpssOptions 'SPSS Options
Dim objSpssDoc As ISpssDocuments 'SPSS Documents
Dim objSpssDat As ISpssDataDoc 'SPSS Data Doc
Dim objSpssSyn As ISpssSyntaxDoc 'SPSS Syntax Doc
Dim objSpssOut As ISpssOutputDoc 'SPSS Output Doc
Dim objSpssPrn As ISpssPrintOptions 'SPSS Print Options
Dim objSpssOut1 As ISpssItems 'SPSS Syntax Navigator Tree
Dim objSpssOut2 As ISpssItem 'SPSS Syntax Navigator Tree
Item
Dim objPivotTable As PivotTable 'Pivot table
Dim FileExt2 As String 'output extension
FileExt2=".spo"
Dim FileToSave As String 'complete name of file to save
Dim TOCFile As String 'complete name of table of
contents file
Dim ItmIndx As Integer 'item counter
Dim GenIndx As Integer 'index counter
Dim ItmType As Integer 'item type
Dim tblcntr As Integer 'table counter
Dim sNewLabel As String 'replacement table title
'run from the open SPSS application
Set objSpssApp = GetObject(,"SPSS.Application")
Set objSpssOpt = objSpssApp.Options
'get the designated output window
Set objSpssOut = objSpssApp.GetDesignatedOutputDoc
'open TOC File
Open "CurrentTOC.txt" For Output As #1
tblcntr = 1
Wait 2
'collect and label and change table titles and write to file
Set objSpssOut1 = objSpssOut.Items
ItmIndx = objSpssOut1.Count
For GenIndx = 0 To (ItmIndx - 1) Step 1
Set objSpssOut2 = objSpssOut1.GetItem(GenIndx)
ItmType = objSpssOut2.SPSSType
If ((ItmType = 5) And (objSpssOut2.Visible)) Then
objSpssOut2.Selected=True
Print #1, "Table ";tblcntr;": ";objSpssOut2.Label
sNewLabel = "Table " & tblcntr & ": " &
objSpssOut2.Label
objSpssOut2.Label = sNewLabel
Set objPivotTable = objSpssOut2.ActivateTable
sNewLabel = "Table " & tblcntr & ": " &
objPivotTable.TitleText
objPivotTable.TitleText = sNewLabel
'objSpssOut2.Deactivate
objSpssOut2.Selected=False
tblcntr = tblcntr + 1
End If
Next GenIndx
Wait 2
'close TOC File
Close #1
Wait 2
'save designated output window to file of same name as the syntax
FileToSave = GetFilePath$ (,"sps","FIND Output FILE MATCH",0) &
FileExt2
objSpssOut.SaveAs(FileToSave)
TOCFile = FileToSave & "TOC.txt"
Name "CurrentTOC.txt" As TOCFile
Wait 2
End Sub
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
David Lindsay
Sent: Saturday, September 10, 2005 4:04 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Table number
Thanks to Ray's help sometime ago I wrote a macro that
produces tables.
Now, I want to give each table a number (i.e. Table 15)
in the table title.
I cannot see how to produce coding that increments each
time the table macro is run. I guess it would also be
useful to be able to specify the starting number incase
I have to re-run a table.
Some help would be gratefully received.
Thanks,
--
David Lindsay