title: Convert Excel Worksheet to CSV & store filename in TXT. Skip filename on future script execution
body: <p>I would like to make a batch script, that <p>
  a.) converts XLS or XLSX to CSV
  b.) writes the excel's name into a TXT
  c.) skips this excel on any consecutive runs of the script</p>
  
  <p><strong>Complete script below the question</strong></p>
  
  <hr>
  
  <p>I currently have the following:</p>
  
  <p>1.) The Batch File that runs the converter (courtesy of someone in the link below)</p>
  
  <pre><code>FOR /f "delims=" %%i IN ('DIR *.xlsx /b') DO ExcelToCSV.vbs "Sheet2" "%%i" "%%i.csv" "CSVlog.txt"
  </code></pre>
  
  <p>2.) The Converter by ScottF &amp; Christian Lemer at <a href="https://stackoverflow.com/questions/1858195/">Convert XLS to CSV on command line</a></p>
  
  <pre><code>if WScript.Arguments.Count &lt; 3 Then
  WScript.Echo "Please specify the sheet, the source, the destination files. Usage: ExcelToCsv &lt;sheetName&gt; &lt;xls/xlsx source file&gt; &lt;csv destination file&gt;"
  Wscript.Quit
  End If
  
  csv_format = 23
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  
  src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(1))
  dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(2))
  CSVlog = objFSO.GetAbsolutePathName(WScript.Arguments.Item(3))
  
  Dim oExcel
  Set oExcel = CreateObject("Excel.Application")
  
  Dim oBook
  Set oBook = oExcel.Workbooks.Open(src_file)
  
  oBook.Sheets(WScript.Arguments.Item(0)).Select
  oBook.Application.Columns("A:J").NumberFormat = "@"
  oBook.SaveAs dest_file, csv_format
  
  oBook.Close False
  
  objFSO.opentextfile(CSVlog)
  CSVlog.Write(dest_file)
  oExcel.Quit
  </code></pre>
  
  <p>The script quits with an error, "Object required: 'CSVlog', after having made the CSV.</p>
  
  <p>Could someone please help me </p>
  
  <p>1.) remove the "xlsx" from the CSV name? (currently the CSVs are stored as "Workbook.xlsx.csv")</p>
  
  <p>2.) write the xlsx name the CSVlog.txt</p>
  
  <p>3.) Query the log file before starting the conversion. And if the file has already been processed, not to process it again.</p>
  
  <p>thanks in advance,
  Henning</p>
  
  <hr>
  
  <p><strong>Complete Script</strong> <p>
  Hi, for all that need it, attached the whole script. <p>
  This script will look for *.xls in its folder and convert them to *.csv.<p>
  You can replace *.xls below to *.xlsb, *.xlsm, *.xlsm <p></p>
  
  <p>Thanks to <i>ScottF, Christian Lemer and MC ND</i> for the originals and the help!
  <p><b>Batch file:</b></p>
  
  <pre><code>:: Feed something into CSVLog to avoid "no search strings" errors
  echo ;%date: =_%_%time: =_% &gt;&gt; CSVLog.txt
  
  FOR /f "delims=" %%i IN (
      'DIR *.xls /b ^| findstr /v /r /x /g:CSVlog.txt'
  ) DO ExcelToCSV.vbs "Details" "%%i" "%%~ni.csv" "CSVlog.txt"
  </code></pre>
  
  <p>I have added /r because /l would have issues on some filenames.
  If you are having issues, replace <p>
  <code>findstr /v /r /x /g:CSVlog.txt</code> 
  with <p></p>
  
  <p><code>findstr /v /l /x /g:CSVlog.txt'</code> <p>
  <b>VB Script</b> <p></p>
  
  <pre><code>REM based on ScottF &amp; Christian Lemer at https://stackoverflow.com/questions/1858195/
  REM &amp; MC ND at https://stackoverflow.com/questions/23381408/
  REM script will convert a defined Worksheet from an XLS into CSV.Then store the name of the XLS in the CSVlog.txt.
  REM it will not process any XLS that are found in the CSVlog.txt
  if WScript.Arguments.Count &lt; 4 Then
  WScript.Echo "Please specify the sheet, the source, the destination files. Usage: ExcelToCsv &lt;sheetName&gt; &lt;xls/xlsx source file&gt; 
  
  &lt;csv destination file&gt;"
  Wscript.Quit
  End If
  
  csv_format = 23
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  
  src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(1))
  dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(2))
  CSVlog = objFSO.GetAbsolutePathName(WScript.Arguments.Item(3))
  entry = Wscript.Arguments.Item(1)
  
  Dim oExcel
  Set oExcel = CreateObject("Excel.Application")
  
  Dim oBook
  Set oBook = oExcel.Workbooks.Open(src_file)
  
  oBook.Sheets(WScript.Arguments.Item(0)).Select
  oBook.Application.Columns("A:J").NumberFormat = "@"
  oBook.SaveAs dest_file, csv_format,,,,,,,,,,True
  
  oBook.Close False
  
  oExcel.Quit
  objFSO.opentextfile(CSVlog,8,True).WriteLine(Wscript.Arguments.Item(1))
  </code></pre>
  
  <p><p>
  This will make a semi-colon separated "CSV". To make a comma-separated CSV,<p>
  remove <code>,,,,,,,,,,True</code> from <code>oBook.SaveAs dest_file, csv_format,,,,,,,,,,True</code></p>