我有一个运行excel宏的vbscript。一切似乎都是正确的,但它并没有像我希望的那样工作。任务开始但随后只是连续运行而没有做任何事情。
让我告诉你我拥有的一切......我没有得到任何错误,它只是运行不正常。
任务计划程序时间轴
之后它只是说“正在运行”并且没有执行任何操作。
我的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
非常感谢任何帮助。提前谢谢!
路径网络:
答案 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
它应该有效