Wednesday, January 08, 2020

PowerShell and Excel

I wrote a PowerShell script to start MS Excel process and manipulate an Excel file. This PS works perfectly fine when it is executed interactively by a user account. However when using Windows task scheduler, it throws the following errors:

Microsoft Excel cannot access the file
There are several possible reasons:
The file name or path does not exist.
The file is being used by another program.
The workbook you are trying to save has the same name as a currently open workbook.

In turns out, I need to create a directory named: Desktop
In the following locations:

64-Bit OS
C:\Windows\SysWOW64\config\systemprofile\Desktop

32-Bit OS
C:\Windows\System32\config\systemprofile\Desktop