'Jenkins Error "Microsoft Excel cannot access the file"

I am using jenkins to run a .bat file that is in location

C:\Users\foo\Desktop\xxx.bat

which internally

  1. copies from another machine an excel
  2. calls a vbs script found in D:
D:\foo\Newtask.vbs

that opens a file:

C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm

The error I am getting is

  1. For the first excel: The system cannot find the path specified

  2. For the second New.xlsm:

D:\foo\Newtask.vbs(14, 1) Microsoft Excel: Microsoft Excel cannot access the file 'C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm'. 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

I find it odd that jenkins can access and run .bat in foo user's directory while it cannot find C:\Users\foo\Desktop\xxx\xxx\xxx\New.xlsm --> I checked it exists.

When running the .bat manually i have no problem.

Any ideas?



Solution 1:[1]

I had the same issue. Solution from this page worked https://techcommunity.microsoft.com/t5/sql-server-support-blog/error-8216-microsoft-office-excel-cannot-access-the-file-8217/ba-p/317477

...x64: Create the following directory: C:\Windows\SysWOW64\config\systemprofile\Desktop

x86: Create the following directory: C:\Windows\System32\config\systemprofile\Desktop...

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 Milan Vodehnal