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.



80 posts

Master Geek
+1 received by user: 3


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!
705 posts

Ultimate Geek
+1 received by user: 16

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
49106 posts

Uber Geek
+1 received by user: 4127

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...






80 posts

Master Geek
+1 received by user: 3


  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 (-:



80 posts

Master Geek
+1 received by user: 3


  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:




News »

Trending now »
Hot discussions in our forums right now:

MH 17 "shot down" all dead
Created by joker97, last reply by turnin on 22-Jul-2014 16:56 (196 replies)
Pages... 12 13 14


Huge Fuss, didn't even make it a year.
Created by networkn, last reply by Glassboy on 22-Jul-2014 19:50 (121 replies)
Pages... 7 8 9


Skinny's new aggressive ad campaign
Created by Yabanize, last reply by Yabanize on 22-Jul-2014 23:35 (52 replies)
Pages... 2 3 4


Cunliffe on Holiday
Created by networkn, last reply by oxnsox on 22-Jul-2014 18:43 (33 replies)
Pages... 2 3


Insulation - good deals?
Created by Fred99, last reply by Handle9 on 19-Jul-2014 18:08 (15 replies)

Wetback - Radiators - Gas Instant - Heating System DIY
Created by WanaGo, last reply by WanaGo on 22-Jul-2014 23:24 (36 replies)
Pages... 2 3


VDSL router/modem to replace Telecom model
Created by Davoid, last reply by Inphinity on 22-Jul-2014 12:18 (12 replies)

Telecom and temporarily moving
Created by Tel69, last reply by NonprayingMantis on 19-Jul-2014 21:34 (12 replies)


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.