1

I would like to open a excel file from a python script, and wait that the user closes the Excel application.

xl = win32com.client.DispatchEx("Excel.Application")
xl.Visible = True
wb = xl.Workbooks.Open(dir+"/my.csv")
wb.RefreshAll()
#wait for xl closes
#continue scripts

But I could find any method in win32com to do it.

user2858691
  • 125
  • 7
  • see http://stackoverflow.com/a/19390275/3025412. Does it help? – themistoklik Dec 20 '16 at 13:40
  • Thanks, I read it, but it doesn't state if a wait can be made on the Workbooks resources such as in the subporocess module. It can only be used to make an active wait by polling if excel has an instance running. I am looking for an event/notify way – user2858691 Dec 20 '16 at 14:29
  • If you can get a reference on the workbook you need you can check in a while loop until that reference becomes invalid (ie the user closes the workbook). That is however blocking the rest of the script from executing. This is what you want, right? – themistoklik Dec 20 '16 at 19:54
  • yes it is. But using a while loop is not the better way. A good way, is to have a notification when excel close is a good way, such as the wait method of the subprocess module. – user2858691 Dec 21 '16 at 09:10
  • is there a way to get a subprocess object from a workbook object? – user2858691 Dec 21 '16 at 10:47
  • furthermore solution stackoverflow.com/a/19390275/3025412, tests if an Excel instance runs. But I want to wait a specific instance closes and then continue my execution. – user2858691 Dec 21 '16 at 14:36
  • Finaly I used the method describe above but combined with `wb.FullName` to try to get the full name of the excel file name. if the file is closed it raises an exception thus I can know which Excel application is closed or open – user2858691 Dec 27 '16 at 16:47

0 Answers0