'Begin Description ' Export Pivot Tables, Charts and/or IGRAPH of spo files meeting a "path\\filemask" criteria to HTM ' 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, all Pivot Tables (and/or Charts) are selected then ' exported To an HTM file named output1.htm ' Similarly, all Pivot Tables of myoutput.spo are exported to myoutput.htm. ' All the files meeting the given mask and located in the given folder are processed 'End Description ' posted to SPSSX-L list on 2001/11/08 by rlevesque@videotron.ca ' http://pages.infinit.net/rlevesqu/index.htm Option Explicit ' The target items (those to be exported to HTML) are decided based on the following constants ' Modify next 3 lines to fit your requirements Const bolTABLE = True 'True means export all such items Const bolCHART = True 'False means do not export Const bolIGRAPH = True 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 Dim bolNoFiles As Boolean If MsgBox("NB: All currently open Output Window will be closed! OK?",vbOkCancel + vbExclamation) _ = vbCancel Then Exit Sub bolNoFiles = True 'define file path and mask strPath ="g:\\temp\\" strFileMask ="out*.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 Set objOutputDoc = objSpssApp.OpenOutputDoc(strPath & strFname) bolNoFiles = False objOutputDoc.Visible = True ' Select all target items Call SelectItems(objOutputDoc) Call ExportTargetItemsToHTML(objOutputDoc, strPath, strFname) ' To conserve memory, close all but the designated output document '(using a simple "objOutputDoc.Close" crashes spsswin.exe!) intCount = objDocuments.OutputDocCount For I = 0 To intCount - 1 Set objOutputDoc = objDocuments.GetOutputDoc(I) If Not objOutputDoc.Designated Then objOutputDoc.Close End If Next 'Get next output file name strFname = Dir$() Wend If bolNoFiles=True Then MsgBox("The path " & strPath & strFileMask & " does not match any files",vbOK + vbCritical) Set objOutputDoc = Nothing End Sub '**************************** Sub ExportTargetItemsToHTML ( _ objOutputDoc As ISpssOutputDoc, _ strPath As String, _ strFname As String) '**************************** ' Export selected Objects to HTML ' Name of HTM file is same as the name of the SPO file Dim strFile As String On Error GoTo ErrorHand ' Define the name of the file containing the HTML output strFile = strPath & Left(strFname,InStr(strFname,".")) & "htm" Kill strFile 'Kill file if it already exists ' Export all selected objects to HTML objOutputDoc.ExportDocument (SpssSelected, strFile, SpssFormatHtml, True) Exit Sub ErrorHand: Select Case Err Case 10101 'File could not be killed Resume Next Case Else Debug.Print Err & " " & Err.Description MsgBox "Sorry, an error occured! You will have to try to solve the problem." Exit Sub End Select End Sub '**************************** ' To select items in the Output which meets the strCriteria Sub SelectItems(objOutput As ISpssOutputDoc) '**************************** Dim objItems As ISpssItems Dim objItem As ISpssItem Dim lngCount As Long Dim i As Integer Set objItems = objOutput.Items lngCount = objItems.Count ' Find and select items meeting strCriteria For i = lngCount - 1 To 0 Step -1 Set objItem = objItems.GetItem(i) Debug.Print objItem.SPSSType Select Case objItem.SPSSType Case 1 'Chart objItem.Selected = bolCHART Case 5 'Pivot Table objItem.Selected = bolTABLE Case 10 'IGRAPH objItem.Selected = bolIGRAPH Case Else objItem.Selected = False End Select Next End Sub