Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.



82 posts

Master Geek
+1 received by user: 5


Topic # 109538 21-Sep-2012 15:48 Send private message

Hi - I've got a large number of Lotus 123 Wk4 files (in lots of folders) and need to convert them all to XLS files. I found this on the Scripting Centre-


' Script name: XLS_SaveAsSYLK.vbs
' Created on: 07/07/2011
' Author: Dennis Hemken
' Purpose: Opens an existing Microsoft Excel Document
' and then saves the file in SYLK format.


Dim AppExcel
Dim OpenWorkbook
Const xlS = 1
Const xlSYLK = 2
Set AppExcel = CreateObject("Excel.Application")
AppExcel.Visible = False
Set OpenWorkbook = AppExcel.Workbooks.Open("C:\temp\Temp.wk4")
OpenWorkbook.SaveAs "C:\temp\newfile", xls
OpenWorkbook.Close
Set OpenWorkbook = Nothing
AppExcel.Quit
Set AppExcel = Nothing

Which works well against 1 specified file name - How do i loop through all the files in the folder structure, converting them and leaving the converted file in the same folder as the source wk4 file?

Thanks for any pointers! (-: 

 

Create new topic
Choice!
711 posts

Ultimate Geek
+1 received by user: 24

Trusted
Subscriber

  Reply # 689525 21-Sep-2012 15:56 Send private message

You'd modify that script so that the existing logic is moved into a function, then you'd loop through the file system, calling that function every time you find a file wk4 file.

BDFL
49896 posts

Uber Geek
+1 received by user: 4615

Administrator
Trusted
Geekzone
Subscriber

  Reply # 689530 21-Sep-2012 16:15 Send private message

What about something like (fix the syntax but you get the idea)

  
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("path")

For Each objSubfolder In objFolder.SubFolders
For Each objFile in For objSubfolder.Files
' Repeat logic
Next
Next

Set objItem = Nothing
Set objSubfolder = Nothing
Set objFolder = Nothing
Set objFSO = Nothing


This code will take some time to run, depending on how Excel perform on each file...






82 posts

Master Geek
+1 received by user: 5


  Reply # 689544 21-Sep-2012 16:54 Send private message

thanks guys - that has put me on the right track - once I get the syntax tidied up I will post for future ref (-:



82 posts

Master Geek
+1 received by user: 5


  Reply # 689735 21-Sep-2012 22:53 Send private message

Got there in the end (-;

' Script to convert all files in source folder and subfolders to XLS files from
' Lotus 123 WK4 files.
' Requires Excel 2003 (NOT Excel 2007 or2010)
' Files are converted but keep orginal name but with XLS appended.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = "c:\lotus"

Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

Wscript.Echo strFolderName

arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")

For Each objFile in colFiles
If objFile.Extension = "wk4" or objFile.Extension = "WK4" Then
Wscript.Echo objFile.Name
ExcelConvert objfile.Name
End If

Next

For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next

Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
Wscript.Echo
Wscript.Echo objFolder2.Name
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "'")

For Each objFile in colFiles
If objFile.Extension = "wk4" or objFile.Extension = "WK4" Then
Wscript.Echo objFile.Name
End If
Next

GetSubFolders strFolderName
Next
End Sub


Sub ExcelConvert(SourceFile)
Dim AppExcel
Dim OpenWorkbook
Const xlS = 1

Set AppExcel = CreateObject("Excel.Application")

AppExcel.Visible = False

Set OpenWorkbook = AppExcel.Workbooks.Open(SourceFile)
DestFile = Sourcefile & ".xls"
OpenWorkbook.SaveAs DestFile, xls

OpenWorkbook.Close
Set OpenWorkbook = Nothing

AppExcel.Quit
Set AppExcel = Nothing
End Sub

Create new topic




Twitter »
Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





Trending now »

Hot discussions in our forums right now:

Another Trade Me competitor: SellShed
Created by freitasm, last reply by mattwnz on 20-Oct-2014 15:16 (22 replies)
Pages... 2


Why would Suresignal calls be worse quality than non-Suresignal calls from the same location?
Created by Geektastic, last reply by gzt on 20-Oct-2014 15:08 (37 replies)
Pages... 2 3


American legal jurisdiction in New Zealand
Created by ajobbins, last reply by gzt on 20-Oct-2014 21:03 (16 replies)
Pages... 2


Picture resizing on the forum
Created by Jase2985, last reply by freitasm on 18-Oct-2014 13:32 (13 replies)

Internet question...
Created by Geektastic, last reply by Geektastic on 17-Oct-2014 22:59 (40 replies)
Pages... 2 3


Just bought a TiVo online. No wireless adaptor. Will a standard one work? Or do I need the TiVo one ?
Created by Limerick, last reply by graemeh on 20-Oct-2014 16:03 (11 replies)

iPad Air 2 and iPad Mini 3. Gonna get one?
Created by Dingbatt, last reply by alexx on 20-Oct-2014 13:34 (45 replies)
Pages... 2 3


Why do people keep thinking National are doing a great job?
Created by sxz, last reply by BurningBeard on 20-Oct-2014 11:06 (155 replies)
Pages... 9 10 11



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.

Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.