4

I'm facing a odd behavior when trying to Open and Save an Excel file. The message, when opening and saving is always the same, doesn't matter if it's in a network drive or in the C:\.

(-2147352567, 'Exception occurred.', (0, u'Microsoft Excel', u"Microsoft Excel cannot access the file 'C:\\Temp\\7541dd6ff7a65348995d4a94e1d78c61.xlsx'. There are several possible reasons:\n\n\u2022 The file name or path does not exist.\n\u2022 The file is being used by another program.\n\u2022 The workbook you are trying to save has the same name as a currently open workbook.", u'xlmain11.chm', 0, -2146827284), None)

I do believe that the problem may be linked to the environment and settings of the user running the script, because the script is being run by a scheduler. When I run using runas /profile user:<user> I don't get any error. The user can write in both the Network folder and C:/.

The scheduler also uses the same user, but there are small differences in the environment variables: It's missing the HOMEPATH: \Windows\system32 and HOMEDRIVE, everything is the same otherwise.

The code does run in other machines. The main difference is the version of Excel: Microsoft Excel 2013 (15.0.4569.1504) MSO (15.0.4569.1506) 64-bit , while other machines are using Excel 2010.

I'm using Python 2.7.14 and pywin32=227, all using a virtual environment in each machine so everything is the same. I do think it's something related to the user environment but I don't know what yet.

Does anyone have any idea?

Eug_Zazou
  • 155
  • 1
  • 11

0 Answers0