【问题标题】:External data does not load in excel when scheduled from scheduled task从计划任务计划时,外部数据不会加载到 Excel 中
【发布时间】: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


    【解决方案1】:

    太棒了!

    您使用的是哪个版本的 Windows?大约一周前我遇到了同样的问题,我遇到了一个非常奇怪的解决方案...... :)

    尝试将文件夹添加到 C:\Windows\SysWOW64\config\systemprofile,简单命名为“Desktop”...如果您运行 32 位版本的 Windows,请执行相同操作,但路径必须包含 system32 而不是系统WOW64... “无论用户是否登录都运行”现在将完成这项工作......如果你的脚本中有一个日志记录功能,你会看到脚本在 Excel 命令周围的某个地方停止......我不知道为什么会这样,简直是……

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 2014-06-21
      • 1970-01-01
      • 2016-10-30
      • 2019-10-03
      • 2020-01-28
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多