On 10/08/2011 13:46, David Robinow wrote:
<code>
from win32com.client import Dispatch

app = Dispatch ("Excel.Application")
app.Visible = 1 # Watch what's going on
wb = app.Workbooks.Add ()
# [Sheet1], [Sheet2], [Sheet3]
wb.Sheets.Add (After=wb.Sheets (3))
# [Sheet1], [Sheet2], [Sheet3], [Sheet4]

</code>

Do you see the same? And is that what you expected?
  I see [Sheet4], [Sheet1], [Sheet2], [Sheet3]

Python2.7.2,  Excel 2007

Interesting. I'm running Excel 2003; might make a difference.
Hold on... Nope; my colleague's 2007 install does the same
as mine. Another theory; could it be (oddly) to do with
static vs dynamic dispatch...

Aha! And it is. If I force the use of dynamic dispatch, one
of the several differences is that the new sheet appears
first as you described. Frankly, I'm not even going to try
to determine why that is. My advice is that you change your
dispatch line to:

app = win32com.client.gencache.EnsureDispatch ("Excel.Application")

and go from there. I suspect it will work.

TJG

_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to