I haven't automated Excel, but I'm using some code from Microsoft's Speech API that may be similar enough to get you started:
ListenerBase = win32com.client.getevents("SAPI.SpInProcRecoContext")
class Listener(ListenerBase):
def OnRecognition(self, _1, _2, _3, Result):
"""Callback whenever something is recognized."""
# Work with Result
def OnHypothesis(self, _1, _2, Result):
"""Callback whenever we have a potential match."""
# Work with Result
then later in a main loop:
while not self.shutting_down.is_set():
# Trigger the event handlers if we have anything.
pythoncom.PumpWaitingMessages()
time.sleep(0.1) # Don't use up all our CPU checking constantly
Edit for more detail on the main loop:
When something happens, the callback doesn't get called immediately; instead you have to call PumpWaitingMessages(), which checks if there are any events waiting and then calls the appropriate callback.
If you want to do something else while this is happening, you'll have to run the loop in a separate thread (see the threading module); otherwise it can just sit at the bottom of your script. In my example I was running it in a separate thread because I also had a GUI running; the shutting_down variable is a threading.Event you can use to tell the looping thread to stop.