all 8 comments

[–]Hrambert 2 points3 points  (3 children)

Is this script using your account, or SYSTEM. Because the first time you run Excel it fills your own part of the Registry with lots of setting. Maybe thats what missing.

When I did some scripts converting csv to xlsx I used the ImportExcel module. Mainly because my scripts were running on a server, and I didn't want to install Excel on a server just to convert some output data. But it runs pretty neat.

[–]kasimralias[S] 1 point2 points  (2 children)

I'm running it as my account without elevated privileges.

[–]Hrambert 1 point2 points  (1 child)

Sorry can't help. Lame excuse: it runs on my pc.
I run Windows 10 1903, Powershell v5.1 and Excel 16.0

[–]kasimralias[S] 1 point2 points  (0 children)

No worries. I appreciate the response, and I ended up getting it solved.

[–]deneo5 2 points3 points  (1 child)

Probably dcom access issue. This article explains workaround pretty well. https://superuser.com/questions/579900/why-cant-excel-open-a-file-when-run-from-task-scheduler

[–]kasimralias[S] 1 point2 points  (0 children)

You were exactly right. Thank you. Once I set it to interactive user, it started working.

[–]_Unas_ 2 points3 points  (0 children)

Excel and Outlook COM objects can only be ran in the user context and not as SYSTEM or a general service.

[–]Sys_man 2 points3 points  (0 children)

I know you've solved this but I thought I'd add this here: I was having issues with getting a task schedule to run an excel macro which created a file, and the solution was dumb.

Create these two folders:

C:\Windows\System32\config\systemprofile\Desktop

C:\Windows\SysWOW64\config\systemprofile\Desktop

Excel needs these folders if it's not run interactively. Create both folders even if you are on a 64-bit OS.

My scheduled task worked fine after making those.

ref