[python-win32] Need help with converting a simple Excel macro
kc106_2005-pywin32 at yahoo.com
kc106_2005-pywin32 at yahoo.com
Sat Aug 5 04:55:22 CEST 2006
Hi list,
I have a need to copy 3 rows of data from the top of
my Excel spreadsheet to another location. I would
have throught that this should be very straightforward
since I've done a fair amount of Excel/Python
programming. Unforturnately, I am stuck on this one.
The VB Macro says I need to:
Range("1:1,2:2,3:3").Select
Range("A3").Activate
Selection.Copy
Rows("20:20").Select
ActiveSheet.Paste
So, I figure the Python code would be something like:
<xlApp determined already>
1) xlSheet=xlApp.ActiveWorkbook.ActiveSheet
2) xlSel=xlSheet.Range("1:1,2:2,3:3").Select()
3) #xlSel=xlSheet.Range("A3").Activate()
4) xlSel.Copy()
5) xlSheet.Rows("20:20").Select()
6) xlSheet.Paste()
Unfortunately, this doesn't work. After line 2, xlSel
becomes "True" - not a "Selection" and so the code
fails at line 4). I am not sure why I have to do the
"Activate" on line 3 but it didn't matter, the code
still fails at line 4.
What am I doing wrong?
Any help is greatly appreciated.
Regards,
--
John Henry
More information about the Python-win32
mailing list