2016-09-25 48 views
0

我有一个咕嘟咕嘟任务手表Excel文件并运行的VBScript:转换Excel文件CSV - 不能剿Excel的提示窗口

咕嘟咕嘟代码:

.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格式重新保存文件时的提示跳转,它工作正常。 就像“有这个名字的文件已经存在,你想保存它吗?”

节省,因为咕嘟咕嘟观察者将触发执行代码之前,我不能删除一个文件。 oBook.Close SaveChanges = TrueoExcel.DisplayAlerts = False没有工作。

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

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

P.S.我不介意使用任何其他脚本,除了PowerShell的 - Set-ExecutionPolicy remotesigned导致错误

的Set-ExecutionPolicy:访问被拒绝的注册表项HKEY_LOCAL_MACHINE \ Microsoft.PowerShell”

+0

回复:PowerShell的 - 你需要从提升的提示 –

回答

4

无论是节能

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

或设置DisplayAlerts = False压制提示(这也强制替换现有文件)之前删除现有文件:

oExcel.DisplayAlerts = False 
oBook.SaveAs dest_file, csv_format 
+0

1.运行'设置ExecutionPolicy'因为咕嘟咕嘟守望引发不必要的代码执行 2.我已经添加了DisplayAlerts我不能删除文件=错误的地方。 谢谢! – Doc999tor