Run Same Syntax on 17 Zipped Files
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 77 78 79 80 81 82 83 84 85 86 87 88 89 | 'Below goes an example which sequentially opens 17 'zipped files And executes the same Command sequence For 'Each. It Is an SPSS script. 'Rafael Osorio in newsgroup on 2000/1/31 Option Explicit Dim objSpssApp As Object Dim strCommands As String Dim idx As Integer Dim PnadZip, PnadSav, PnadAge Sub Main 'Matrix with name of zipfiles PnadZip = Array ("PNAD76Familia.zip", "Pnad77Familia.zip", "PNAD78Familia.zip", "PNAD81Familia.zip", "PNAD82Familia.zip", "PNAD84Familia.zip", "PNAD85Familia.zip", "PNAD86Familia.zip", "PNAD87Familia.zip", "PNAD88Familia.zip", "PNAD89Familia.zip", "PNAD90Familia.zip", "PNAD92Familia.zip", "PNAD93Familia.zip", "PNAD95Familia.zip") ReDim Preserve PnadZip (17) PnadZip(15) = "PNAD96Familia.zip" PnadZip(16) = "PNAD97Familia.zip" 'Matrix with names of files inside zipfiles PnadSav = Array ("PNAD76Fam.sav", "Pnad77Fam.sav", "PNAD78Fam.sav", "PNAD81Fam.sav", "PNAD82Fam.sav", "PNAD84Fam.sav", "PNAD85Fam.sav", "PNAD86Fam.sav", "PNAD87Fam.sav", "PNAD88Fam.sav", "PNAD89Fam.sav", "PNAD90Fam.sav", "PNAD92Fam.sav", "PNAD93Fam.sav", "PNAD95Fam.sav") ReDim Preserve PnadSav (17) PnadSav(15) = "PNAD96Fam.sav" PnadSav(16) = "PNAD97Fam.sav" 'Matrix with var name that changes through years PnadAge = Array ("v2105", "v173", "v2805", "v805", "v805", "v805", "v805", "v805", "v805", "v805", "v805", "v805", "v03034", "v03034", "v03034") ReDim Preserve PnadAge (17) PnadIdade(15) = "v8005" PnadIdade(16) = "v8005" Set objSpssApp = CreateObject("SPSS.Application") For idx = 0 To 16 'Call and run pkunzip Shell("C:\\pkunzip c:\\pnadsfamilia\\" & PnadZip(idx) &" " &PnadSav(idx) &" C:\\pnadsfamilia") 'wait while pkunzip unzips, PIF config should be set to Close window after finished While idx = idx On Error GoTo desvio AppActivate "pkunzip" Wend desvio: 'Puts appropriate GET command on string strCommands = "GET FILE = 'c:\\pnadsfamilia\\" &pnadsav(idx) &"' /KEEP pesfam tpfamfp sitdom sitfam nfd paren nagreg npensi nempre npaemp " PnadAge(idx) &" ." 'Execute string objSpssApp.ExecuteCommands strCommands, False 'Wait processing While objSpssApp.IsBusy Wend 'Here you make a call to another sub with desired commands, Or Write them here strCommands = "NEW FILE." objSpssApp.ExecuteCommands strCommands, False While objSpssApp.IsBusy Wend 'erases unzipped file Kill "c:\\pnadsfamilia\\" &PnadSav(idx) Next idx End Sub |
Related pages
...