On 20/02/2006 7:46 PM, Tim Golden wrote:
> [yeswanty devi]
> 
> | Hello all,
> |          if we have number of excel sheets in a workbook.can 
> | we access a selected sheet in the workbook. when i try to 
> | acces it always goes to the last sheet. 
> 
> I assume this is the kind of thing you want:
> (somewhat exaggerated example, but ...)
> 
> <code>
> import os
> import win32com.client
> 
> xl = win32com.client.Dispatch ("Excel.Application")
> #
> # Create a new workbook with a default
> #  number of sheets (probably 3)
> #
> wb = xl.Workbooks.Add ()
> print wb.Sheets.Count
> 
> sheet0 = wb.Sheets[0]
> sheet1 = wb.Sheets[1]
> sheet2 = wb.Sheets[2]
> 
> sheet0.Name = "First sheet"
> sheet1.Name = "Second sheet"
> sheet2.Name = "Third sheet"
> 
> wb.SaveAs (Filename="c:\\temp\\test.xls")
> wb.Close ()
> xl.Quit ()
> 
> os.startfile ("c:\\temp\\test.xls")
> 
> </code>

Errrmmm ... I got the impression that the OP wanted to access a 
particular sheet in an existing workbook, not to create a new workbook.
The OP didn't say whether he wanted to select by name or number; perhaps 
  some kind soul could tell him both :-)

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

Reply via email to