RangeFromPoint Method

Microsoft Word Visual Basic

RangeFromPoint Method

       

Returns the Range or Shape object that is located at the point specified by the screen position coordinate pair. If no range or shape is located at the coordinate pair specified, the method returns Nothing.

expression.RangeFromPoint(x, y)

expression   Required. An expression that returns a Window object.

x   Required Long. The horizontal distance (in pixels) from the left edge of the screen to the point.

y   Required Long. The vertical distance (in pixels) from the top of the screen to the point.

Example

This example creates a new document and adds a five-point star. It then obtains the screen location of the shape and calculates where the center of the shape is. Using these coordinates, the example uses the RangeFromPoint method to return a reference to the shape and change its fill color.

Dim pLeft As Long
Dim pTop As Long
Dim pWidth As Long
Dim pHeight As Long
Dim newShape As Object
Dim newDoc As New Document

With newDoc
    .Shapes.AddShape msoShape5pointStar, _
        288, 100, 100, 72
    .ActiveWindow.GetPoint pLeft, pTop, _
        pWidth, pHeight, .Shapes(1)
    Set newShape = .ActiveWindow.RangeFromPoint(pLeft _
        + pWidth * 0.5, pTop + pHeight * 0.5)
    newShape.Fill.ForeColor.RGB = RGB(80, 160, 130)
End With