任务计划程序正在运行但没有完成或正常工作VBscript

时间:2013-11-26 14:54:31

标签: excel vba vbscript

我有一个运行excel宏的vbscript。一切似乎都是正确的,但它并没有像我希望的那样工作。任务开始但随后只是连续运行而没有做任何事情。

让我告诉你我拥有的一切......我没有得到任何错误,它只是运行不正常。

任务计划程序时间轴

  • 事件110 任务由用户触发(任务计划程序为用户“tsee”启动了“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”任务“\ Test”实例。
  • 事件319 任务引擎收到启动任务的消息
  • 事件100 任务已启动 - 任务计划程序为用户“METRO \ tsee”启动了“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”“\ Test”任务的实例。
  • 事件200 操作已启动 - 任务计划程序在实例“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”中启动了操作“C:\ Users \ tsee \ Desktop \ vbsTest \ runTest.vbs”任务“\测试”。
  • 事件129 已创建任务进程 - 任务计划程序启动任务“\ Test”,实例“C:\ Windows \ System32 \ WScript.exe”,进程ID为8964.

之后它只是说“正在运行”并且没有执行任何操作。

我的VBScript :( runTest.vbs)

Dim xlApp
Dim xlBook

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\\fileserver\homeshares\Tsee\My Documents\Programming\Task Scheduler\runTask.xlsm", 0, True)
xlApp.Run "runTaskTest"
xlBook.Close
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing

我的Excel工作表和宏:(runTask.xlsm)

Sub runTaskTest()
    Dim erow As Long

    erow = Cells(Rows.Count, "A").End(xlUp).Row

    Cells(erow + 1, 1).FormulaR1C1 = "This test was successful : " & Now

    ThisWorkbook.Save
End Sub

非常感谢任何帮助。提前谢谢!

路径网络:enter image description here

1 个答案:

答案 0 :(得分:1)

继续评论

修改您的VBS文件

Dim xlApp
Dim xlBook

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\\fileserver\homeshares\Tsee\My Documents\Programming\Task Scheduler\runTask.xlsm", 0, False)

xlApp.DisplayAlerts = False
xlApp.Visible = False

xlApp.Run "runTaskTest"

xlBook.Saved = True
xlBook.Save

xlBook.Close
xlApp.Quit


Set xlBook = Nothing
Set xlApp = Nothing

和你的宏

Sub runTaskTest()
    Dim erow As Long
    erow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
    Sheets(1).Cells(erow + 1, 1).Value = "This test was successful : " & Now

    ThisWorkbook.Saved = True
    ThisWorkbook.Save
End Sub

它应该有效