I have set up a task in task manager that calls a single .bat file (which then calls a .vbs) to tackle 4 easy steps:
.bat file:
Step 1: Grabs a handful of .xlsx files from over the network and copies them locally with a datestamp
COPY "\\prime\d$\Cognos Reports\eMoney\Client_Ethic.xlsx" "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_Client_Ethic.xlsx"
COPY "\\prime\d$\Cognos Reports\eMoney\InvestmentDepositAccounts_Ethic.xlsx" "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_InvestmentDepositAccounts_Ethic.xlsx"
COPY "\\prime\d$\Cognos Reports\eMoney\LiabilityAccounts_Ethic.xlsx" "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_LiabilityAccounts_Ethic.xlsx"
COPY "\\prime\d$\Cognos Reports\eMoney\Relationship_Ethic.xlsx" "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_Relationship_Ethic.xlsx"
Step 2: Calls the .vbs file to convert all .xlsx files in the dir to .csv
The call: FOR /f "delims=" %%i IN ('DIR .xlsx /b') DO to-csv.vbs "%%i" "%%~ni.csv"
if WScript.Arguments.Count < 2 Then
WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv <xls/xlsx source file> <csv destination file>"
Wscript.Quit
End If
csv_format = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
oExcel.DisplayAlerts = False
Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
oBook.SaveAs dest_file, csv_format
oBook.Close False
oExcel.Quit
Step 3: Sends the .csv files via WS SFTP Pro and move the sent .csv files to an archive folder
"C:\Program Files (x86)\Ipswitch\WS_FTP 12\wsftppro.exe" -s "local:D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_*.csv" -d "eMoney:/Ethic:/" -move "D:\Cognos Reports\FTPOUT\eMoney Archive\" -quiet
Step 4: Delete the .xlsx files
DEL "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_Client_Ethic.xlsx"
DEL "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_InvestmentDepositAccounts_Ethic.xlsx"
DEL "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_LiabilityAccounts_Ethic.xlsx"
DEL "D:\Batch\%DATE:~4,2%%DATE:~7,2%%DATE:~-4%_Relationship_Ethic.xlsx"
When I run the process manually by running the .bat as admin it works just fine (so the code shouldn't be the issue). However, when I try to run it from Task Scheduler with the same admin account it completes step 1 and then just hangs in Running status with no errors. So I can see the xlsx files were pulled over, but there are no csv files converted.
I've even tried splitting the task into 4x separate bat files so it's guaranteed to finish each step before attempting the next... so it's not trying to convert before the files transfer over the network. I've also tried changing the task to run cmd and provide /c as the parameter. Same result.
We've had several issues with the Office install on this box and have tried several fresh installs, but it still isn't working via task scheduler. We've tried both Excel 2016 and Office 365 with disabling automatic updates.
Server is 2012R2 if that matters. I'm scratching my head on this one...