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.




102 posts

Master Geek


# 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
926 posts

Ultimate Geek

Trusted

  # 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 - Memuneh
64861 posts

Uber Geek

Administrator
Trusted
Geekzone
Lifetime subscriber

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




 
 
 
 




102 posts

Master Geek


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



102 posts

Master Geek


  # 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 and LinkedIn »



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 »

Chorus to launch Hyperfibre service
Posted 18-Nov-2019 15:00


Microsoft launches first Experience Center worldwide for Asia Pacific in Singapore
Posted 13-Nov-2019 13:08


Disney+ comes to LG Smart TVs
Posted 13-Nov-2019 12:55


Spark launches new wireless broadband "Unplan Metro"
Posted 11-Nov-2019 08:19


Malwarebytes overhauls flagship product with new UI, faster engine and lighter footprint
Posted 6-Nov-2019 11:48


CarbonClick launches into Digital Marketplaces
Posted 6-Nov-2019 11:42


Kordia offers Microsoft Azure Peering Service
Posted 6-Nov-2019 11:41


Spark 5G live on Auckland Harbour for Emirates Team New Zealand
Posted 4-Nov-2019 17:30


BNZ and Vodafone partner to boost NZ Tech for SME
Posted 31-Oct-2019 17:14


Nokia 7.2 available in New Zealand
Posted 31-Oct-2019 16:24


2talk launches Microsoft Teams Direct Routing product
Posted 29-Oct-2019 10:35


New Breast Cancer Foundation app puts power in Kiwi women's hands
Posted 25-Oct-2019 16:13


OPPO Reno2 Series lands, alongside hybrid noise-cancelling Wireless Headphones
Posted 24-Oct-2019 15:32


Waikato Data Scientists awarded $13 million from the Government
Posted 24-Oct-2019 15:27


D-Link launches Wave 2 Unified Access Points
Posted 24-Oct-2019 15:07



Geekzone Live »

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


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



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.