karelsmits
Technical User
Dear All,
I am trying to convert csv files to xls files. The csv files should be converted in batch mode, meaning that I have loads of csv files in a folder that keep being updated from time to time, and need to be converted to xls. In other words it is a complete folder of csv-files that need to be converted to xls files.
I found a script online which does exactly that. It opens the file in the background with Excel and saves it as an xls file. It is as if I open the file in Excel and save it as xls. The difference is that it is done automatically with that script.
Problem is: the script, which i attached, does only 1 specified file at a time. I need to be able to have a whole folder converted.
Please let me know what you guys think of it, you do not have to use for a basis the below script if you have a better way of doing it.
Thank you very much.
SCRIPT:
==============================================
==============================================
Option Explicit
Const vbNormal = 1
DIM objXL, objWb, objR ' Excel object variables
DIM Title, Text, tmp, i, j, file, name, savename
file = "IBRENTAL.csv"
name = "IBRENTAL"
savename = "c:\rjm\IBRENTAL.xls"
Function GetPath
' Retrieve the script path
DIM path
path = WScript.ScriptFullName ' Script name
GetPath = Left(path, InstrRev(path, "\"))
End Function
' create an Excel object reference
Set objXL = WScript.CreateObject ("Excel.Application")
objXL.WindowState = vbNormal ' Normal
objXL.Height = 300 ' height
objXL.Width = 400 ' width
objXL.Left = 40 ' X-Position
objXL.Top = 20 ' Y-Position
objXL.Visible = true ' show window
' Load the Excel file from the script's folder
Set objWb = objXl.WorkBooks.Open(GetPath+file)
' Get the loaded worksheet object
Set objWb = objXL.ActiveWorkBook.WorkSheets("IBRENTAL")
objWb.Activate ' not absolutely necessary (for CSV)
'WScript.Echo "worksheet imported"
objxl.columns("B:B").numberformat="0000000"
objxl.columns("C:C").numberformat="00000"
' turn of those annoying warning messages
OBJXL.DISPLAYALERTS = fALSE
'wscript.echo savename
' xlWorkbookNormal
objxl.ActiveWorkbook.SaveAs savename, &HFFFFEFD1
objXl.Quit()
Set objXL = Nothing
Set objWB = Nothing
Set objR = Nothing
I am trying to convert csv files to xls files. The csv files should be converted in batch mode, meaning that I have loads of csv files in a folder that keep being updated from time to time, and need to be converted to xls. In other words it is a complete folder of csv-files that need to be converted to xls files.
I found a script online which does exactly that. It opens the file in the background with Excel and saves it as an xls file. It is as if I open the file in Excel and save it as xls. The difference is that it is done automatically with that script.
Problem is: the script, which i attached, does only 1 specified file at a time. I need to be able to have a whole folder converted.
Please let me know what you guys think of it, you do not have to use for a basis the below script if you have a better way of doing it.
Thank you very much.
SCRIPT:
==============================================
==============================================
Option Explicit
Const vbNormal = 1
DIM objXL, objWb, objR ' Excel object variables
DIM Title, Text, tmp, i, j, file, name, savename
file = "IBRENTAL.csv"
name = "IBRENTAL"
savename = "c:\rjm\IBRENTAL.xls"
Function GetPath
' Retrieve the script path
DIM path
path = WScript.ScriptFullName ' Script name
GetPath = Left(path, InstrRev(path, "\"))
End Function
' create an Excel object reference
Set objXL = WScript.CreateObject ("Excel.Application")
objXL.WindowState = vbNormal ' Normal
objXL.Height = 300 ' height
objXL.Width = 400 ' width
objXL.Left = 40 ' X-Position
objXL.Top = 20 ' Y-Position
objXL.Visible = true ' show window
' Load the Excel file from the script's folder
Set objWb = objXl.WorkBooks.Open(GetPath+file)
' Get the loaded worksheet object
Set objWb = objXL.ActiveWorkBook.WorkSheets("IBRENTAL")
objWb.Activate ' not absolutely necessary (for CSV)
'WScript.Echo "worksheet imported"
objxl.columns("B:B").numberformat="0000000"
objxl.columns("C:C").numberformat="00000"
' turn of those annoying warning messages
OBJXL.DISPLAYALERTS = fALSE
'wscript.echo savename
' xlWorkbookNormal
objxl.ActiveWorkbook.SaveAs savename, &HFFFFEFD1
objXl.Quit()
Set objXL = Nothing
Set objWB = Nothing
Set objR = Nothing