将Excel文件转换为CSV – 不能压缩Excel提示窗口

我有一个Gulp任务观看Excel文件并运行VBScript:

口令代码:

.pipe(shell([ 'XlsToCsv.vbs test test.xlsx test.csv' ])) 

VBScript代码:

 If WScript.Arguments.Count < 3 Then WScript.Echo "Please specify the sheet, the source, the destination files. Usage: ExcelToCsv <sheetName> <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(1)) dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(2)) Dim oExcel Set oExcel = CreateObject("Excel.Application") Dim oBook Set oBook = oExcel.Workbooks.Open(src_file) oBook.Sheets(WScript.Arguments.Item(0)).Select oBook.SaveAs dest_file, csv_format oBook.Close False oExcel.Quit 

它工作正常,除了当我以CSV格式重新保存文件的提示跳转。 像“这个名字的文件已经存在,你想保存吗?

我不能保存之前删除以前的文件,因为Gulp观察器将触发代码执行。 oBook.Close SaveChanges = TrueoExcel.DisplayAlerts = False不起作用。

我需要在每次保存时静静地运行这个脚本。

我应该添加什么命令到脚本?

PS我不介意使用任何其他脚本,PowerShell – Set-ExecutionPolicy remotesigned会导致错误

Set-ExecutionPolicy:访问registry项HKEY_LOCAL_MACHINE … \ Microsoft.PowerShell被拒绝

在保存之前删除现有的文件

 If objFSO.FileExists(dest_file) Then objFSO.DeleteFile dest_file oBook.SaveAs dest_file, csv_format 

或者设置DisplayAlerts = False以禁止提示(这也强制replace现有的文件):

 oExcel.DisplayAlerts = False oBook.SaveAs dest_file, csv_format