Dim aaaXLSX_to_CSV _
, bDebug _
, oFS _
, oSh _
, sCSV _
, sDir _
, sFullName _
, sMsg _
, sXLSX _
, zzzXLSX_to_CSV
'-
Sub Help()
Dim vResult
sMsg = _
"Assumes:" & vbLF & _
"- an XLSX with a single tab" & vbLF & _
"- sheet expands to full window."
vResult=oSh.Popup _
(sMsg, _
7, _
WScript.ScriptName, _
vbYesNo+vbDefaultButton2)
If vResult<>vbYes Then
Set oSh=Nothing
Set oFS=Nothing
WScript.Quit
End If
End Sub
'-
Sub ccSleep(seconds)
cmd = "%COMSPEC% /c ping -n " & _
1 + seconds & " 127.0.0.1>nul"
oSh.Run cmd,0,1
End Sub
'-
Sub XLS_to_CSV(sFullName)
sDir=Split(sFullName, "\")
sXLSX=chr(34) & sFullName & chr(34)
If bDebug Then msgbox "sXLSX[" & sXLSX & "]"
sCSV= _
chr(34) & replace(sFullName,".xlsx",".csv") & chr(34)
If bDebug Then msgbox "sCSV[" & sCSV & "]"
oSh.Run "excel " & sXLSX
While Not _
oSh.AppActivate _
("Microsoft Excel - " & sDir(UBound(sDir)) )
ccSleep 1
Wend
oSh.AppActivate _
("Microsoft Excel - " & sDir(UBound(sDir)) )
On Error Resume Next
oFS.DeleteFile replace(sCSV,chr(34),"")
oSh.Sendkeys "%(FA){Tab}c{enter 3}"
While Not _
oSh.AppActivate _
("Microsoft Excel - " & _
Replace(sDir(UBound(sDir)),".xlsx",".csv") )
ccSleep 1
Wend
oSh.AppActivate _
("Microsoft Excel - " & _
Replace(sDir(UBound(sDir)),".xlsx",".csv") )
oSh.Sendkeys "%{F4}"
ccSleep 1
oSh.SendKeys "N"
End Sub
'-
' Main
'bDebug=vbTrue
Set oSh=CreateObject("WScript.Shell")
Set oFS=CreateObject("Scripting.FileSystemObject")
'
Help
'
For Each sFullName in WScript.Arguments
XLS_to_CSV sFullName
Next
'
Set oFS = Nothing
Set oSh = Nothing
WScript.Quit