On 10/08/2011 11:15, A. S. wrote:
I've worked with pywin32 and up to now inspecting the Excel macro editor
and translating commands worked fine, but now I cannot manage to add a
sheet at the correct position in Excel.

My test program is

from win32com.client import Dispatch

app=Dispatch("Excel.Application")
app.Workbooks.Add()
app.ActiveWorkbook.Sheets.Add(After=app.ActiveWorkbook.Sheets(3))

Which adds the sheet at the incorrect position. Is there a trick? How
come Excel gets confused?

Well, you don't say what "at the incorrect position" means for you, but
it appears to work for me. One small hint is that Workbooks.Add returns
the new workbook so you don't have to do app.ActiveWorkbook all over
the place. In summary, this works for me:

<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?

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

Reply via email to