' the 6 is the constant for 'CSV' format, 51 is for 'xlsx' SrcExt = objFSO.GetExtensionName(srcFile) Set objFSO = CreateObject("Scripting.FileSystemObject") Usage: " & WScript.ScriptName & " SourcePath.xls*|csv" WScript.Echo "Error! Please specify at least one source path. WScript.Quit(10) '* 10 Is the error code I use to indicate there was a user abort (1 because wasn't successful, + 0 because the user chose to exit)Īll of these answers helped me construct the following script which will automatically convert XLS* files to CSV and vice versa, by dropping one or more files on the script (or via command line). SResponse = MsgBox (sPrompt,vbYesNoCancel,sTitle) STitle = "Unrecognized File Type Encountered" OFSO.GetAbsolutePathName(sFilename) & vbCRLF ![]() "The path returned by the system was:" & vbCRLF & _ "The unrecognized file was:" & vbCRLF & _ "Cancel - Abort any further conversions and exit this script" & vbCRLF & _ "No - Will pass the file to excel regardless of extension" & vbCRLF & _ "Yes - Will skip all further files that don't have a. "Do you want to skip this and all other unrecognized files? (Will only prompt this once)" & vbCRLF & _ "A filename was received that doesn't appear to be an Excel Document." & vbCRLF & _ OExcelFile.SaveAs sThisDestination, iCSV_Format SAbsoluteDestination = Replace(sAbsoluteSource,sExtension,"",oSheet.Name) SAbsoluteSource = oFSO.GetAbsolutePathName(sFilename) If (PromptForSkip(sFilename,oExcel)) then STest = Mid(sExtension,1,2) '* first 2 letters of the extension, vb's missing a Like operator SExtension = oFSO.GetExtensionName(sFilename) Set oFSO = CreateObject("Scripting.FileSystemObject") ![]() Set oExcel = CreateObject("Excel.Application") ' 10 for file skipped (or user abort if script returns 10) xl* files on me to export each sheet as CSV Open Notepad, create a file called XlsToCsv.vbs and paste this in: '* Usage: Drop. Here is a version that will handle multiple files drag and dropped from windows.īased on the above works by Christian Lemer
0 Comments
Leave a Reply. |