0
問題是我製作了一個腳本,用於打開並刷新我excel中的數據。 數據是來自PHD服務器的外部數據我使用安裝在excel上的插件獲取此數據。 所有工作正常,直到我嘗試與任務調度程序安排腳本。當我安排它爲「只在用戶登錄時運行」它工作正常。但是當我嘗試將其安排爲「運行用戶已登錄或不是」時,它不更新數據。 (它打開excel並保存它,但沒有數據變化)當從計劃任務計劃時,外部數據無法在Excel中加載
它設置在作爲桌面的虛擬機上,甚至當我登錄時也需要完成更新。
腳本的代碼(即正常工作時,我manualy啓動它)
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個代碼塊形成腳本。