Glad it’s working! Your Python code and the Excel application are running in separate processes that (usually) only communicate via COM, not the windows messaging system. When Excel wants to quit it posts a WM_QUIT message to its OWN message queue which, once processed, will terminate the main Excel application thread’s message loop. The Excel process will then terminate (usually). Your Python code may or may not have a message loop. Calling PumpMessages() creates a message loop in your Python application’s main thread. It is there simply to stop your code running through to completion and exiting. It also allows execution of other routines in your code. You have to send a quit message to this loop yourself when you know you are done with it and you want your application to terminate. Excel doesn’t know much about your Python calling code (and certainly not whether your code has a message loop) except that your code has notified Excel (using the WithEvents() call) that it wants Excel to fire the supplied callback whenever an event occurs. Your Python code then decides if it cares about the Event, otherwise ignoring it. That is why you have to write a specific handler for OnBeforeClose and also decide what to do when the event is fired. Excel can’t decide that for you. Best DS Sent from my iPhone On 30 Nov 2024, at 17:28, Gauthier ABRIAL <g_abr...@hotmail.com> wrote:
|
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32