Hey. What I'm working on is first generating a excel from csv, then I'm trying to do some simple (yeah right) formatting on it (like autofit, freezepanes, set border, fill color)... but I'm having trouble with it. But right now I'm just trying to save the damn thing. Wondering if anyone can help me.
Here is some of the code:
'Generating Excelsheet from csv file Dim objExcel Set objExcel = Wscript.CreateObject("Excel.Application") objExcel = csvToExcel()
' Saving as Excel-file On Error Resume Next objExcel.ActiveWorkbook.SaveAs "H:\CsvToExcel\kopi1.xls" If Err.Number <> 0 Then On Error GoTo 0 Wscript.Echo "Spreadsheet could not be saved as h:\kopi1.xls " Wscript.Echo "The path may be invalid." End If On Error GoTo 0 objExcel.ActiveWorkbook.Close
' Quit Excel. objExcel.Application.Quit
'------------------------------------------- Private Function csvToExcel()
Dim Args Dim Shell Dim sValue Dim strFn Dim sCmd Dim aIntSet(3)
Set Args = WScript.Arguments If Args.Count < 1 then WScript.Quit End If
Set Shell = WScript.CreateObject("WScript.Shell")
' code that turns csv to excel.......(regRead()...regWrite... etc.) '............. '........ '... '..... '.........
WScript.Quit
End Function '----------------------------------
The function csvToExcel() alone generates the excel-sheet with the values from the csv-file, but I can't do any formatting on it afterwards, nor save it. My plan is to first save it as a xls file (if it is possible), then do the formatting (which works great when I use it on a pure Excel.Application object). Any tips?
If you insist on diong the work in *function* csvToExcel(), you'll have to assign the return value by "Set objExcel = csvToExcel()" and you shouldn't do [code] WScript.Quit ' <<< that's bad End Function [code]