Export (0) Print
Expand All

Window.RangeFromPoint Method (Word)

Returns the Range or Shape object that is located at the point specified by the screen position coordinate pair.

expression .RangeFromPoint(x, y)

expression Required. A variable that represents a Window object.

Parameters

Name

Required/Optional

Data Type

Description

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.

Return Value

Object

If no range or shape is located at the coordinate pair specified, the method returns Nothing.

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

Concepts

Other resources

Show:
© 2015 Microsoft