Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 416
pandita Avatar asked Sep 06 '13 02:09

pandita


1 Answers

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.

like image 157
Don Avatar answered Sep 21 '22 20:09

Don