Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Roy,
I wasn't sure how you had your command line set up at the start so I suggested the command line option. My personal preference would be to place a shortcut to the script in my SendTo folder which would allow me to right click a csv file from Windows Explorer, send it into the shortcut and have the xls file created. You can also use drag and drop into the script or you can invoke the script from within a batch file. If you've disabled the vbs file association for security reasons, you might need a different command line that would include either cscript.exe or wscript.exe to launch the vbs file and then the argument. Steve "Roy" wrote in message ... Thanks Steve, I'll give your suggestion a shot and see which I am most comfortable with. I appreciated everyone's responses and suggestions. You guys are great! Roy "Steve Yandl" wrote: Here is a slightly different approach. I create a vbScript file named CSVtoXL.vbs which I stored in C:\Scripts. The content of the vbs file is between the dotted lines below. I feed the script a csv file named "C:\Test\RawTable.csv with the command line C:\Scripts\CSVtoXL.vbs "C:\Test\RawTable.csv" The script opens the csv file in Excel, saves it as an xls file with the same file name and path as the csv file except for the extension and then closes Excel. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Const xlWorkbookNormal = -4143 ' Only run script if it has been fed If WScript.Arguments.Count = 0 Then WScript.Echo "Need a file as a command line argument" WScript.Quit End If fileCSV = WScript.Arguments.Item(0) Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FileExists(fileCSV) Then WScript.Quit End If If Not Lcase(fso.GetExtensionName(fileCSV)) = "csv" Then WScript.Quit End If strFileXL = fso.GetParentFolderName(fileCSV) & "\" & _ fso.GetBaseName(fileCSV) & ".xls" Set objExcel = CreateObject("Excel.Application") objExcel.DisplayAlerts = False objExcel.Workbooks.OpenText fileCSV objExcel.Application.ActiveWorkbook.SaveAs strFileXL, xlWorkbookNormal objExcel.Quit _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Steve Yandl "Roy" wrote in message ... I often load CSV files into Excel and then re-save them as Excel Workbooks (*.xls) format. The loading of the CSV file is handled by a command-line that invokes Excel and loads the CSV. After the CSV is loaded into Excel it would be VERY nice if a macro could be executed that would then save the CSV in XLS format, instead of doing the SAVE As manually. Suggestions would be welcome. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to Insert Current Date into cell - Macro to "Save As" | Excel Worksheet Functions | |||
Macro to Save without the Save Message | Excel Discussion (Misc queries) | |||
ASP: Open Excel File with Macro, Allow Macro to run, and then save | Excel Programming | |||
Save As macro | Excel Programming | |||
Prompted to save changes after macro save - why? | Excel Programming |