RangeFromPoint Method 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 myShape 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 myShape = .ActiveWindow.RangeFromPoint(pLeft _
        + pWidth * 0.5, pTop + pHeight * 0.5)
    myShape.Fill.ForeColor.RGB = RGB(80, 160, 130)
End With