Using pywin32, what is the difference between Dispatch and DispatchEx?

pandita picture pandita · Sep 6, 2013 · Viewed 12.1k times · Source

When opening e.g. a spreadsheet with pywin32, I found two options to do so:

excel1 = win32com.client.DispatchEx('Excel.Application')
wb = excel1.Workbooks.Open('myxls.xls')

or I could do

excel2 = win32com.client.Dispatch('Excel.Application')
wb = excel2.Workbooks.Open('myxls.xls')

and I'm wondering if this makes any difference. The docstrings don't help me much either:

>>> w32.Dispatch.__doc__
'Creates a Dispatch based COM object.\n '

>>> w32.DispatchEx.__doc__
'Creates a Dispatch based COM object on a specific machine.\n  '

In this site they suggest that DispatchEx might be for remote access.

Does it make any difference which method I use when I'm simply trying to automate spreadsheets on my own PC?

Answer

Don picture Don · Sep 9, 2013

It depends on what you want. If Excel is already open, using dispatch will create a new tab in the open Excel instance. If Excel is already open, using dispatchEx will open a new instance of Excel.