Solved

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

Posted on 2014-02-13
4
710 Views
Last Modified: 2014-02-19
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
Comment
Question by:NNiicckk
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
No way to do this in a pure batch (BAT) script solution.  Would a vbscript (VBS) script solution be acceptable?

~bp
0
 

Author Comment

by:NNiicckk
Comment Utility
Yes, a VBS script would be acceptable.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
PowerShell is another option. The code is nearly the same as in VBS.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now