By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,529 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

pywin32 COM Problem with Excel Range Offset?

P: n/a
I'm hoping that someone here can give me some insight into a problem I'm
running into with Python, pywin32 and Excel. All-in-all using Python and
pywin32 is great but I've run into a strange problem with the range Offset
property, I'm not getting the correct offset and the returned range is a
single cell and not the same size as the original range.

For example, when I enter the following lines of code in PythonWin :

from win32com.client import Dispatch
xlApp = Dispatch('Excel.Application')
xlApp.Visible = 1
rng1 = xlApp.Range(xlApp.Cells(8,3),xlApp.Cells(20,6))
rng1.Select()
rng2 = rng1.Offset(2,2)
rng2.Select()

rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
defined as D9 instead of E10:H22.

Digging a little further if I look at the cell sizes for the two ranges I
get the following:
rng1.Count 52 rng2.Count

1

What's going on with the Offset property? If I enter the equivalent VBA code
into the Immediate window from the Visaul Basic Editor within Excel I get
the correct behavior. Is this a pywin32 bug?

My configuration:
pywin32 (build 200) {I got the lastest version to see if this would fix
the problem - it didn't}
Python 2.3.3
MS Excel 2002
Windows XP

Any insight into this problem will be greatly appreciated.

Michael
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jr

"Michael Jordan" <mj*****@adobe.com> wrote in message news:tC*******************@newshog.newsread.com...
I'm hoping that someone here can give me some insight into a problem I'm
running into with Python, pywin32 and Excel. All-in-all using Python and
pywin32 is great but I've run into a strange problem with the range Offset
property, I'm not getting the correct offset and the returned range is a
single cell and not the same size as the original range.

For example, when I enter the following lines of code in PythonWin :

from win32com.client import Dispatch
xlApp = Dispatch('Excel.Application')
xlApp.Visible = 1
rng1 = xlApp.Range(xlApp.Cells(8,3),xlApp.Cells(20,6))
rng1.Select()
rng2 = rng1.Offset(2,2)
rng2.Select()

rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
defined as D9 instead of E10:H22.

Digging a little further if I look at the cell sizes for the two ranges I
get the following:
rng1.Count 52 rng2.Count

1

What's going on with the Offset property? If I enter the equivalent VBA code
into the Immediate window from the Visaul Basic Editor within Excel I get
the correct behavior. Is this a pywin32 bug?

My configuration:
pywin32 (build 200) {I got the lastest version to see if this would fix
the problem - it didn't}
Python 2.3.3
MS Excel 2002
Windows XP

Any insight into this problem will be greatly appreciated.

Michael


Use: GetOffset(2, 2) instead.
For some reason gen.py changes "Offset()" to
"GetOffset()"

HTH
jr

Jul 18 '05 #2

P: n/a
Thanks jr! That did the trick, I now get the offset range that I want.
Thanks again for the assistance.

Michael
"jr" <gr******@ix.netcom.com> wrote in message
news:GL***************@newsread1.news.pas.earthlin k.net...

"Michael Jordan" <mj*****@adobe.com> wrote in message

news:tC*******************@newshog.newsread.com...
I'm hoping that someone here can give me some insight into a problem I'm
running into with Python, pywin32 and Excel. All-in-all using Python and
pywin32 is great but I've run into a strange problem with the range Offset property, I'm not getting the correct offset and the returned range is a
single cell and not the same size as the original range.

For example, when I enter the following lines of code in PythonWin :

from win32com.client import Dispatch
xlApp = Dispatch('Excel.Application')
xlApp.Visible = 1
rng1 = xlApp.Range(xlApp.Cells(8,3),xlApp.Cells(20,6))
rng1.Select()
rng2 = rng1.Offset(2,2)
rng2.Select()

rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
defined as D9 instead of E10:H22.

Digging a little further if I look at the cell sizes for the two ranges I get the following:
>> rng1.Count

52
>> rng2.Count

1

What's going on with the Offset property? If I enter the equivalent VBA code into the Immediate window from the Visaul Basic Editor within Excel I get the correct behavior. Is this a pywin32 bug?

My configuration:
pywin32 (build 200) {I got the lastest version to see if this would fix the problem - it didn't}
Python 2.3.3
MS Excel 2002
Windows XP

Any insight into this problem will be greatly appreciated.

Michael


Use: GetOffset(2, 2) instead.
For some reason gen.py changes "Offset()" to
"GetOffset()"

HTH
jr

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.