Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 858
  • Last Modified:

Can I change an Excel file to CSV (Comma Delimited) in a batch

I have daily excel files that I would like to convert to CSV (Comma Delimited) with a batch.  When I manually convert the files I get Microsoft advising me some features are not compatible and do I want to keep the workbook in this format, so I click Yes and it converts to CSV.  Then when I try to close the book, it asks do I want to save changes made to CSV file.  I click no and it closes and I have my CSV file ready to go.  

I would like to create a batch to transfer the files to CSV (Comma Delimited) and close the files.  

Also, if possible I would like to add today's date on each file. Example 2014-02-13

File Names:
Daily Red Wagons
Daily Red Trains
Daily Blue Wagons
Daily Blue Trains

Thanks,
0
NNiicckk
Asked:
NNiicckk
  • 2
1 Solution
 
Bill PrewCommented:
No way to do this in a pure batch (BAT) script solution.  Would a vbscript (VBS) script solution be acceptable?

~bp
0
 
NNiicckkAuthor Commented:
Yes, a VBS script would be acceptable.
0
 
QlemoC++ DeveloperCommented:
PowerShell is another option. The code is nearly the same as in VBS.
0
 
Bill PrewCommented:
Here's a VBS approach, let me know if it doesn't make sense.

Const cExcelCSV = 6

strDir = "B:\EE\EE28363894\Files\"
strExt = ".xls"
strCSV = ".csv"
arrList = Array("Daily Red Wagons","Daily Red Trains","Daily Blue Wagons","Daily Blue Trains")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False

For Each strFile in arrList
   strPath = strDir & strFile & strExt
   If objFSO.FileExists(strPath) Then
      Set objWorkbook = objExcel.Workbooks.Open(strPath, False, True)
      objWorkbook.SaveAs Replace(strPath, strExt, strCSV), cExcelCSV
      objWorkbook.Close False
      Set objWorkbook = Nothing
   End If
Next

objExcel.Quit
Set objExcel = Nothing
Set objFSO = Nothing

Open in new window

~bp
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now