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.



81 posts

Master Geek
+1 received by user: 4


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

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

Uber Geek
+1 received by user: 4347

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






81 posts

Master Geek
+1 received by user: 4


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



81 posts

Master Geek
+1 received by user: 4


  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:

CGA. Is it fair?
Created by BTR, last reply by mattwnz on 21-Aug-2014 14:13 (60 replies)
Pages... 2 3 4


It was hardly 'hacking' was it?
Created by CB_24, last reply by BarTender on 19-Aug-2014 22:36 (87 replies)
Pages... 4 5 6


Shortening the DSL loop on a long driveway
Created by hio77, last reply by hio77 on 20-Aug-2014 21:00 (27 replies)
Pages... 2


Vodafone TV multicast settings on pfSense?
Created by kenkeniff, last reply by chrispchikin on 21-Aug-2014 13:59 (79 replies)
Pages... 4 5 6


Vodafone now charging you to receive a bill via post
Created by stocksp, last reply by richms on 20-Aug-2014 19:28 (79 replies)
Pages... 4 5 6


Free: Smart Button for your Android device
Created by freitasm, last reply by TimA on 21-Aug-2014 12:20 (91 replies)
Pages... 5 6 7


NZ Transport Agency: Snapchat
Created by freitasm, last reply by NzBeagle on 20-Aug-2014 19:27 (44 replies)
Pages... 2 3


Lightbox press event release
Created by freitasm, last reply by dclegg on 21-Aug-2014 10:52 (461 replies)
Pages... 29 30 31



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.