pywin32 COM Problem with Excel Range Offset?

Michael Jordan mjordan at
Wed Feb 11 01:23:53 CET 2004

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))
rng2 = rng1.Offset(2,2)

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
>>> rng2.Count

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.


More information about the Python-list mailing list