我已经使用任务计划程序和 cscript 和 vbscript 运行我的 excel 2000 vba 程序大约一年了。几天前它停止了工作。我可以手动运行程序。每当任务计划程序启动它时,黑色窗口会显示大约 1-2 秒,然后关闭。
我试过注释掉错误处理,但我总是得到相同的结果。我尝试显示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