'workbooks.add fails when vbs-script is called from Task Scheduler

I have some code in VBscript that creates an excel object and adds a workbook to it

Dim oExcel, oWB    
Set oExcel = CreateObject("excel.application")
Set oWB = oExcel.Workbooks.Add()

When I run this myself (using VbsEdit or cscript), it has no issues and does the job. When I make an entry in the Windows 10 Task-Scheduler (or Server 2019 too), run it with setting 'even if the user is offline', it fails with errorcode -2147023170. When I say the user MUST be online (useless, but I tried it anyway) then I get the error 1004 - Unknown runtime error.

I can't figure out what causes this. I presume it's a Office 365 issue, because on an older system (windows server 2012 R2 with office 2016) it runs just fine from the task scheduler.

The account it runs under is administrator, the task runs with the highest priority. The Vbs is not called directly, but using a bat-file with logging. Running a vbs-script directly from the task scheduler seems to get stuck at "running" indefinately :(

Who knows how to fix this ? Thanks, Paul



Solution 1:[1]

How about removing the brackets at the end of Workbooks.Add?

Set oWB = oExcel.Workbooks.Add

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrew