I've never used .RangeFromPoint, but it sure looks like the rangefrompoint's
top/left and shape's top/left are based on different starting points.
If you look at VBA's help for RangeFromPoint, you'll see:
expression An expression that returns a Window object.
x Required Long. The value (in pixels) that represents the horizontal
distance from the left edge of the screen, starting at the top.
y Required Long. The value (in pixels) that represents the vertical distance
from the top of the screen, starting on the left.
And if you look at VBA's help for .addshape, you'll see:
Left, Top Required Single. The position (in points) of the upper-left corner of
the AutoShape's bounding box relative to the upper-left corner of the document.
I googled for .rangefrompoint and found this post:
http://groups.google.co.uk/group/mi...581a401e/?hide_quotes=no#msg_e3a2274d902fc826
(one line in your browser)
======
I put this in a general module:
Option Explicit
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Type POINTAPI
x As Long
y As Long
End Type
Then I added a label from the control toolbox toolbar (so I could use the
mouseover event) on a worksheet.
The I double clicked on that label and pasted this into the code window.
Option Explicit
Private Sub Label1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim MyRange As Object
Dim RetVal As Long
Dim pa As POINTAPI
With Application
.ScreenUpdating = False
With .Windows(1)
RetVal = GetCursorPos(pa)
Set MyRange = .RangeFromPoint(pa.x, pa.y)
Debug.Print pa.x & "--" & pa.y & vbLf & TypeName(MyRange) _
& vbLf & MyRange.Top & "--" & MyRange.Left & vbLf _
& "------"
End With
.ScreenUpdating = True
End With
End Sub
And I got this back:
388--478
OLEObject
204.75--213
------
Then I moved my excel application window.
And I got this:
429--434
OLEObject
204.75--213
------
This sure looks like it's made for web based stuff. If you're something for a
web application, good luck. If you're not, what are you trying to do?