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?