For development purpose, I need to change regularly an Excel
file and to generate a "CSV" file that is a text file where column's elements are separated by TAB
character.
To facilitate my work, I have created following VBS script
'***********************************************************************
'* file: SaveAs.CSV.bat
'***********************************************************************
sInputFile = Wscript.Arguments(0)
WScript.Echo "Excel input file: " & sInputFile
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open(sInputFile)
ex.Application.DisplayAlerts = False
'https://docs.microsoft.com/en-us/office/vba/api/office.msoencoding
wb.WebOptions.Encoding = 28591
ex.Application.DefaultWebOptions.Encoding = 28591
'https://docs.microsoft.com/en-us/office/vba/api/excel.xlfileformat
sOutputFile = Replace(sInputFile & "*",".xlsx*",".txt")
ex.Worksheets(1).SaveAs sOutputFile, 20
ex.ActiveWorkbook.Close
ex.Application.Quit
WScript.Echo "CSV file has been created."
WScript.Quit
To start "CSV" file creation for a specific XLSX file, I have created following BAT file
cscript SaveAs.CSV.vbs "D:\Documents\+Informatique\Application\@Visual Basic.NET\DrawPlanUnifilaire\Plan-Unifilaire.xlsx"
pause
So, I only click on BAT file and a TXT tab separated file is automatically generated from first sheet in XLSX file.
The UNICODE UTF8 characters contained in XLSX file (éèàüäù) are correctly converted to Windows ANSI characters.