简体   繁体   中英

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. Don't remember where as otherwise I would give credit. The script opens an XLS file and saves it as CSV file. 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. 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. No popups or confirmation from me. I would like it to just move on to the next CMD line.

The VBScript file:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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