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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20220430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:39:04  来源:igfitidea点击:

Task Scheduler running but not finishing or working properly VBscript

excelvbavbscript

提问by Adjit

I have a vbscript that runs an excel macro. Everything seems right, but it is not working as I had hoped. The task starts but then just continuously running without doing anything.

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

Let me show you everything I have... I don't get any errors, it just isn't running properly.

让我向您展示我拥有的一切...我没有收到任何错误,只是运行不正常。

Task scheduler Timeline

任务调度器时间线

  • Event 110Task Triggered by user (Task Scheduler launched "{6569c7af-fed8-456b-8c8e-9d1653b8c15a}" instance of task "\Test" for user "tsee".
  • Event 319Task engine received message to start task
  • Event 100Task started - Task Scheduler started "{6569c7af-fed8-456b-8c8e-9d1653b8c15a}" instance of the "\Test" task for user "METRO\tsee".
  • Event 200Action Started - Task Scheduler launched action "C:\Users\tsee\Desktop\vbsTest\runTest.vbs" in instance "{6569c7af-fed8-456b-8c8e-9d1653b8c15a}" of task "\Test".
  • Event 129Created Task Process - Task Scheduler launch task "\Test" , instance "C:\Windows\System32\WScript.exe" with process ID 8964.
  • 用户触发的事件 110任务(任务计划程序为用户“tsee”启动了任务“\Test”的“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”实例。
  • 事件 319任务引擎收到启动任务的消息
  • 事件 100任务已启动 - 任务计划程序已启动用户“METRO\tsee”的“\Test”任务的“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”实例。
  • 事件 200操作已启动 - 任务计划程序在任务“\Test”的实例“{6569c7af-fed8-456b-8c8e-9d1653b8c15a}”中启动了操作“C:\Users\tsee\Desktop\vbsTest\runTest.vbs”。
  • 事件 129创建的任务进程 - 任务计划程序启动任务 "\Test",进程 ID 为 8964 的实例 "C:\Windows\System32\WScript.exe"。

After that it just says "running"and doesn't execute anything.

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

My VBScript: (runTest.vbs)

我的 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

My excel Sheet and Macro: (runTask.xlsm)

我的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

Any help would be much appreciated. Thanks in advance!

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

Path network: enter image description here

路径网络: 在此处输入图片说明

采纳答案by Adjit

Further to the comments

进一步的评论

modify your VBS file

修改你的 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

and your macro

和你的宏

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

and it should work

它应该工作