Apply autofit
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 | Sub Main 'Purpose: apply Autofit to all Pivot Tables 'Assumptions: there is an open Output Doc (Navigator) 'Effects: adjust Pivot Table row and column widths 'Inputs: none 'Return Values: none Dim objDocuments As ISpssDocuments ' SPSS documents. Dim objOutputDoc As ISpssOutputDoc ' Output document Dim objItems As ISpssItems ' Output Navigator items Dim objPivotTable As PivotTable ' The Pivot Table Dim i As Integer 'Get list of documents in SPSS. Set objDocuments = objSpssApp.Documents ' Get designated document only if there is at least one output document. ' Omitting this test results in a error message. If objDocuments.OutputDocCount > 0 Then 'Get the currently designated output document. Set objOutputDoc = objSpssApp.GetDesignatedOutputDoc Else 'If no navigator window exists, quit the script. 'comment the following line out and the script will go away silently. MsgBox "Please open an output window before running this script.", vbExclamation, "Script Error" Exit Sub End If ' Get the outline tree from the Navigator. Set objItems = objOutputDoc.Items ' Get each item in the Navigator. For i = 0 To objItems.Count - 1 Set objItem = objItems.GetItem(i) 'Get each item in turn. If objItem.SPSSType = SPSSPivot Then 'Check to see if it's a PivotTable Set objPivotTable = objItem.ActivateTable() 'Activate the pivot table. objPivotTable.UpdateScreen = False 'Defer drawing until later. '************************************************************* '* Insert the body of your script here, replacing everything '* between the rows of asterisks. 'Here's where we do the work: objPivotTable.Autofit '************************************************************* 'do all the drawing at once objPivotTable.UpdateScreen = True 'Clean-up time: Always remember to Deactivate when finished. 'note that it's the Item, not the Pivot Table, which is deactivated, 'just as it was the Item that was Activated. objItem.Deactivate End If Next End Sub |
Related pages
...
Navigate from here