N
Nick Hebb
I have a function that iterates through the Shapes collection as
follows:
For Each shp In ActiveSheet.Shapes ' shp is Dim'ed as Shape
t = shp.Top
b = t + shp.Height
l = shp.Left
r = l + shp.Width
Debug.Print shp.Name, t, b, l, r
' do some other stuff
Next
The function wasn't working correctly, so I added the Debug.Print to
examine the values, and they were all wrong! The Debug.Print output
was:
'shp.Name, t, b, l, r:
AutoShape 1 4.08 8.16 4.08 16.32
AutoShape 2 12.24 16.32 4.08 16.32
AutoShape 4 20.4 24.48 4.08 16.32
.... etc.
Next I added a breakpoint to step through it. When I did, the
coordinates were suddenly correct. ?!? So I ran it again with the
breakpoint on the "t = shp.Top" line, toggled the breakpoint off, then
ran it to completion. The Debug.Print output now was:
'shp.Name, t, b, l, r:
AutoShape 1 25.5 51 25.5 102
AutoShape 2 76.5 102 25.5 102
AutoShape 4 127.5 153 25.5 102
.... etc.
These values are all 6.25x the first set. I hadn't changed any of the
shapes on the sheet, and the code in the for-loop does not alter them
in any way. It just reads a few properties.
So it seems that if I give Excel a moment to "catch it's breathe", the
coordinates all get resolved correctly.
Anyone have any clue as to what might be causing this?
Thanks,
Nick Hebb
follows:
For Each shp In ActiveSheet.Shapes ' shp is Dim'ed as Shape
t = shp.Top
b = t + shp.Height
l = shp.Left
r = l + shp.Width
Debug.Print shp.Name, t, b, l, r
' do some other stuff
Next
The function wasn't working correctly, so I added the Debug.Print to
examine the values, and they were all wrong! The Debug.Print output
was:
'shp.Name, t, b, l, r:
AutoShape 1 4.08 8.16 4.08 16.32
AutoShape 2 12.24 16.32 4.08 16.32
AutoShape 4 20.4 24.48 4.08 16.32
.... etc.
Next I added a breakpoint to step through it. When I did, the
coordinates were suddenly correct. ?!? So I ran it again with the
breakpoint on the "t = shp.Top" line, toggled the breakpoint off, then
ran it to completion. The Debug.Print output now was:
'shp.Name, t, b, l, r:
AutoShape 1 25.5 51 25.5 102
AutoShape 2 76.5 102 25.5 102
AutoShape 4 127.5 153 25.5 102
.... etc.
These values are all 6.25x the first set. I hadn't changed any of the
shapes on the sheet, and the code in the for-loop does not alter them
in any way. It just reads a few properties.
So it seems that if I give Excel a moment to "catch it's breathe", the
coordinates all get resolved correctly.
Anyone have any clue as to what might be causing this?
Thanks,
Nick Hebb