簡體   English   中英

如何制作給出錯誤 800A03EC“文件已移動或刪除”的 VBS 文件並忽略該錯誤?

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

我從另一個 Stack Overflow 頁面復制了這個。 不記得在哪里,否則我會給予信任。 該腳本打開一個 XLS 文件並將其保存為 CSV 文件。 但是,有時用戶會在服務運行之前移動或刪除文件,以使用 XML 文件清理文件夾中的所有內容。 如果發生這種情況並且文件丟失,我會收到一個錯誤,導致我的小自動化任務崩潰。 如果.vbs只是忽略文件不存在的錯誤,我會喜歡它。 我沒有彈出窗口或確認。 我希望它繼續前進到下一個 CMD 行。

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

這就是我從自動 CMD 運行它的方式:

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

我嘗試了其他幾個版本。

感謝大家的幫助。 想出了這個。 讓我知道你們是否都看到任何事情完全搞砸了。

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