简体   繁体   English

如何制作给出错误 800A03EC“文件已移动或删除”的 VBS 文件并忽略该错误?

[英]How to make a VBS file giving Error 800A03EC “File was moved or deleted” and ignore the error?

I copied this from another Stack Overflow page.我从另一个 Stack Overflow 页面复制了这个。 Don't remember where as otherwise I would give credit.不记得在哪里,否则我会给予信任。 The script opens an XLS file and saves it as CSV file.该脚本打开一个 XLS 文件并将其保存为 CSV 文件。 However, the files are moved from or deleted sometimes by users before the service runs to clean everything up in the folder with the XML file.但是,有时用户会在服务运行之前移动或删除文件,以使用 XML 文件清理文件夹中的所有内容。 If that happens and a file is missing, I get an error that crashes my little automated task.如果发生这种情况并且文件丢失,我会收到一个错误,导致我的小自动化任务崩溃。 I would like it if the .vbs just ignores the error of the file not existing.如果.vbs只是忽略文件不存在的错误,我会喜欢它。 No popups or confirmation from me.我没有弹出窗口或确认。 I would like it to just move on to the next CMD line.我希望它继续前进到下一个 CMD 行。

The VBScript file: VBScript 文件:

if WScript.Arguments.Count < 2 Then
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit

This is how I run it from an automated CMD:这就是我从自动 CMD 运行它的方式:

XlsToCsv.vbs "location-inputfile.xls" "location-outputfile.csv"

I have tried a few other versions.我尝试了其他几个版本。

Thanks for the help all.感谢大家的帮助。 Came up with this.想出了这个。 Let me know if you all see anything totally messed up.让我知道你们是否都看到任何事情完全搞砸了。

Function FileExists(FilePath)
  Set fso = CreateObject("Scripting.FileSystemObject")
  If fso.FileExists(FilePath) Then
    FileExists=CBool(1)
  Else
    FileExists=CBool(0)
  End If
End Function

If FileExists(Wscript.Arguments.Item(0)) Then
    Dim oExcel
    Set oExcel = CreateObject("Excel.Application")
    Dim oBook
    Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
    oBook.SaveAs WScript.Arguments.Item(1), 6
    oBook.Close False
    oExcel.Quit
Else
  WScript.quit
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM