简体   繁体   中英

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

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

Set oWB = oExcel.Workbooks.Add

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM