所以我看到了this questions并且它无法解决我的问题。我有一个我想要每天运行的计划任务。它打开一个excel工作簿,运行一个宏来更新一些东西,然后永远不会停止运行。
这是VBS脚本。
Option Explicit
ExcelMacroRun
Sub ExcelMacroRun()
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
'xlApp.AskToUpdateLinks = False
xlApp.AlertBeforeOverwriting = False
'~~> Change Path here
Set xlBook = xlApp.Workbooks.Open("P:\Fido\Automated\DailyPrices\DailyPrices_new.xlsm", 0)
xlApp.Run "getPriceData"
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
WScript.Quit
这是宏:
Sub getPriceData()
Application.ScreenUpdating = False
On Error GoTo echk
echk1 = False
Application.Calculation = xlManual
'Import new fund data into Imports page
Worksheets("Import").Activate
Cells.Delete
Workbooks.Open Filename:="P:\FIDO\Automated\DailyPrices\prices.csv"
Windows("prices.csv").Activate
Cells.Select
Selection.Copy
Windows("DailyPrices_new.xlsm").Activate
Worksheets("Import").Activate
Cells.Select
Selection.PasteSpecial Paste:=xlAll
'Import new annuity data into Annuities page
Worksheets("AnnuityImport").Activate
Cells.Delete
Workbooks.Open Filename:="P:\FIDO\Automated\DailyPrices\AnnuityPRA.csv"
Windows("AnnuityPRA.csv").Activate
Cells.Select
Selection.Copy
Windows("DailyPrices_new.xlsm").Activate
Worksheets("AnnuityImport").Activate
Cells.Select
Selection.PasteSpecial Paste:=xlAll
这里有一个代码块,它在excel文件中添加一列。如果列很长并且运行计算,则删除该列。然后它来到文件的这一部分(结束):
Calculate
Application.Calculation = xlAutomatic
Exit Sub
echk:
'MsgBox Error
echk = True
Resume Next
End Sub
无论用户是否登录,它都会设置为运行。即使我自己启动它也会保持运行。我迷失在这里。任何人都可以看到我错过了为什么它不会停止运行?