我一直在使用任務計劃程序和cscript和vbscript運行我的excel 2000 vba程序大約一年。幾天前它停止工作。我可以手動運行程序。每當任務計劃程序啓動它時,黑色窗口將顯示約1-2秒,然後關閉。從任務計劃程序啓動excel工作,現在失敗
我試過評論錯誤處理,但我總是得到相同的結果。 我試過顯示MsgBoxes
,但結果仍然相同。
我在你的論壇上發現了一個更簡單的方法來做到這一點,我試着用相同的結果。
那麼我需要做些什麼來調試呢?
下面是代碼,我從這個論壇的嘗試:
Option Explicit
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("C:\My Documents\___Stocksfilter.xls", 0, True)
xlApp.Run "A_Pick"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo "Finished."
WScript.Quit
這是我一直在使用代碼:
'Script to start my filter.xls program with named macro
'MsgBox "In RunExcel"
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.FeatureInstall = msoFeatureInstallNone
' Open the Workbook
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = "C:\My Documents\___Stocks\filter.xls"
'MsgBox "Opening filter"
on error resume next
Set oWorkBook = myExcelWorker.Workbooks.Open(strWorkerWB)
if err.number <> 0 Then
' Error occurred - just close it down.
MsgBox "open Error occurred"
End If
err.clear
on error goto 0
'MsgBox "Running macro"
Dim strMacroName
strMacroName = "A_Pick"
on error resume next
' Run the macro
myExcelWorker.Run strMacroName
if err.number <> 0 Then
' Error occurred - just close it down.
MsgBox "run macro Error occurred"
End If
err.clear
on error goto 0
' Clean up and shut down
Set oWorkBook = Nothing
myExcelWorker.Quit
Set myExcelWorker = Nothing
Set WshShell = Nothing
歡迎來到[so]。 +1寫得很好的第一個問題。你是在XP還是Win7上運行(不是服務器)?並且當你在沒有 'myExcelWorker.DisplayAlerts = False'的情況下進行調試時,excel會提示正在發生什麼? – 2013-03-09 00:42:24
它運行在我的舊的Windows 98 SE計算機上。它根本沒有顯示任何錯誤信息。但黑色的窗口只是閃爍,我不知道如何捕捉錯誤。我將DisplayAlerts = False與其他UI行一起註釋掉,結果總是完全相同。 – RoseAb 2013-03-09 01:04:25
它在Excel宏的vb腳本中失敗了嗎?你有沒有證實路徑是正確的? – enderland 2013-03-09 01:30:10