【发布时间】:2017-10-30 22:39:59
【问题描述】:
问题是我制作了一个脚本,可以在我的 excel 中打开和刷新数据。 数据是来自 PHD 服务器的外部数据,我使用安装在 excel 上的插件获取这些数据。 在我尝试使用任务调度程序安排脚本之前,一切正常。当我将其安排为“仅在用户登录时运行”时,它工作正常。但是当我尝试将其安排为“运行用户是否登录”时,它不会更新数据。 (它确实会打开 excel 并保存它,但数据没有变化)
它设置在充当桌面的 VM 上,即使我已登录,也需要进行更新。
脚本的代码:(当我手动启动它时工作正常)
Dim oExcel
Set oExcel = CreateObject("Excel.Application") 'launch excel.
oExcel.Visible = True ' makes the aplication visible (if not set to true the data won't be updated)
oExcel.DisplayAlerts = False' disables all excel allerts.
oExcel.AskToUpdateLinks = False 'now excel will not ask you to update links.
oExcel.AlertBeforeOverwriting = False 'excel will not display an alert before overwriting data in a cell.
插件更新数据的代码
Dim addIn
addIn = COMAddIn
Dim automationObject
automationObject = Object
Set addIn = oExcel.COMAddIns("ExcelCompanion")
Set automationObject = addIn.Object
automationObject.UNIF_workbook_refresh
保存和关闭excel的代码
oWorkbook.RefreshAll 'refreshes the workbook
oWorkbook.Save 'saves the updated workoob
oWorkbook.Final = True 'makes the file read-only
oExcel.Quit 'exits excel
Set oWorkbook = Nothing ' destroy the object (minimises damage if the object goes out of scope)
Set oExcel = Nothing ' destroy the object (minimises damage if the object goes out of scope)
这 3 块代码构成了脚本。
【问题讨论】:
标签: excel vbscript scheduled-tasks