I am trying to automate excel operations using python. It is crucial for me to use the Pywin32 library since I am refreshing Queries in Excel. I get an error which corresponds to issues with file permissions.
When I try to run my query from the Task Scheduler, with the appropriate actions and triggers set, and the option 'Run whether user is logged on or not' ,and with highest privileges, I get the following error:
(-2147352567, 'Exception occurred.', (0, 'Microsoft Excel',
"Microsoft Excel cannot access the file 'C:\\Users\\kaivalya\\bot\\test.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.", 'xlmain11.chm', 0, -2146827284), None)
When I run the task with the 'Run only when user is logged on' option, it runs fine. I have tried everything regarding the file and folder level permissions as well, and the folder and file both have Full control permissions for the user Kaivalya, which is the administrator.
I tried the solution at Using windows10 task scheduler to run python script that uses win32 to run excel file. Whenever user is logged in or not , but it doesnt seem to work either
What can I do to make it run? I have already scheduled the task to run with highest privileges.