0

I was trying to run a python script which contains command like this:

wb = xw.Book(r'C:/Users/myUser/Documents/scripts/Analyzer.xlsm')

when I run this python script in windows powershell terminal and through windows remote management in windows 10, it can be run without any issue.

However, after my PC upgrade to windows 11, even I get no error run it through terminal, when I run it through windows remote management, It would give error like:

Traceback (most recent call last):
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 711, in __call__
     return Book(xl=self.xl(name_or_index))
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 219, in __call__
     v = self._inner(*args, **kwargs)
   File "C:\Users\myUser\AppData\Local\Temp\gen_py\3.9\00020813-0000-0000-C000-000000000046x0x1x9.py", line 41316, in __call__
     ret = self._oleobj_.InvokeTypes(0, LCID, 2, (13, 0), ((12, 1),),Index
 pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\main.py", line 4963, in open
     impl = self.impl(name)
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 713, in __call__
     raise KeyError(name_or_index)
 KeyError: 'Analyzer.xlsm'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "C:\Users\myUser\Documents\script\macro_new.py", line 92, in 
     wb = xw.Book(r'C:/Users/myUser/Documents/scripts/Analyzer.xlsm')
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\main.py", line 898, in __init__
     impl = app.books.open(
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\main.py", line 4970, in open
     impl = self.impl.open(
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 745, in open
     xl=self.xl.Open(
   File "C:\Users\myUser\AppData\Local\Programs\Python\Python39\lib\site-packages\xlwings\_xlwindows.py", line 105, in __call__
     v = self.__method(*args, **kwargs)
   File "C:\Users\myUser\AppData\Local\Temp\gen_py\3.9\00020813-0000-0000-C000-000000000046x0x1x9.py", line 41193, in Open
     ret = self._oleobj_.InvokeTypes(1923, LCID, 1, (13, 0), ((8, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename
 pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Microsoft Excel cannot access the file 'C:\\Users\\myUser\\Documents\\script\\Analyzer.xlsm'. There are several possible reasons:\n\n� The file name or path does not exist.\n� The file is being used by another program.\n� The workbook you are trying to save has the same name as a currently open workbook.", 'xlmain11.chm', 0, -2146827284), None)

I update the xlwings version to xlwings-0.30.4, it doesn't help the python environment in my PC is 3.9.13

syx007
  • 1
  • The first error in a trace is the one at the end of the exception. So I would first try to fixed the missing file C:\\Users\\myUser\\Documents\\script\\Analyzer.xlsm. Are you logged into myUser? You could try running the script as an Admin to see if you still get these errors. Right click the PS shortcut and select Run As Admin. – jdweng Apr 12 '23 at 09:04
  • @jdweng First of all, the file is not missing, as I mentioned above, I can run this script without any issue in the powershell terminal but only fail when I tried to run it through windows remote management(Windows RM) – syx007 Apr 13 '23 at 01:35
  • I didn't say the file was missing. I'm implying inside the script you do not have the access right to read the file. Since the file is in myUser only myUser and an Admin can read the file. – jdweng Apr 13 '23 at 09:01
  • @jdweng, when I access the file through windows RM, I use myUser account to login to the PC. I tried to change the folder permission and give full control but it doesn't help. do you know how to access through window RM with admin rights? – syx007 Apr 14 '23 at 01:53
  • The remote and local machine need to be in the same group so you Admin Account is the same on local and remote machine. If you are in a Corporate Network with Group Policy your admin account should work on both local and remote machine. The with a file explorer you should be able to access files on remote machine using \\machine-name\c$\path . You use dollar sign instead of a colon in the path name when you are a Admin. If this works with file explorer it will also work inside a PS script. – jdweng Apr 14 '23 at 02:35

0 Answers0