Jacques
Jacques

Reputation: 31

Win 10 Excel Object Model job fails in Job Scheduler

Windows 10 and Excel 365 patched up to date. Using powershell to run an Excel Object Model session, I open a workbook which contains a query which fetches data from a database to update cells in a worksheet.

$excelObj = New-Object -ComObject Excel.Application
$workBook = $excelObj.Workbooks.Open($bookPath)
$workSheet = $workBook.Sheets.Item("Summary")
$worksheet.Select()
$workBook.RefreshAll()`

At this point, when run from the desktop there's a second or so before the refreshed query data update the worksheet, then the rest of the program runs to normal completion with the updated cell contents.

My problem is that this needs to be run by the Job Scheduler, and when it is, the RefreshAll completes but the worksheet is never updated. The JS job is run using the same login credentials as my desktop, and has been run with the Hidden switch on and off with the same result every time. The Excel itself has been made visible and invisible, again with no success:

$excelObj.visible=$false

or

$excelObj.visible=$true

Can anybody suggest why the worksheet isn't updated when run from the JS, or how I can work around this?

Upvotes: 0

Views: 24

Answers (0)

Related Questions