1

At work, we are all using the same server. When someone else is using an Excel file, another cannot. I have written a Python file to make my work easier but I need to open an Excel file which is used often by others. When I execute the Python file and someone else works in the Excel file I get the following error:

return self.oleobj.InvokeTypes(3174, LCID, 1, (24, 0), ((12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (3, 49), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename pywintypes.com_error: (-2147352567, 'Er is een uitzondering opgetreden.', (0, 'Microsoft Excel', 'Kan geen toegang krijgen tot PythonTest.xlsm.', 'xlmain11.chm', 0, -2146827284), None)

Translated: There occured an exception. Not able to excess PythonTest.xlsm.

I would like my Python script to try to open the Excel file but if someone else is using it waits an tries again to open it a couple of seconds later.

import xlwings
import time

excel_file = xlwings.Book("my_file_path")

# while excel_file is opened by other user:
#     time.sleep(5)
#     try again to open the Excel file

How can I make this happen?

Vitalizzare
  • 4,496
  • 7
  • 13
  • 32
Pascal
  • 23
  • 7
  • I think this answer can be useful: https://stackoverflow.com/a/6826099/14909621 – Vitalizzare Sep 07 '22 at 21:04
  • Thank you Vitalizzare. This points me in the right direction indeed. Using the right search words makes a lot of difference. Thanks a lot :) – Pascal Sep 08 '22 at 14:40

0 Answers0