elementFromPoint Method

       

Given screen coordinates, returns the IHTMLElement object that corresponds to the specified coordinate arguments.

expression.elementFromPoint(x, y)

expression   Required. An expression that returns one of the objects in the Applies To list.

x  Required. A Long that represents a specified point on the horizontal axis.

y  Required. A Long that represents a specified point on the vertical axis.

Remarks

The coordinates correspond to window coordinates (0,0 is the top-left corner of the window). For the elementFromPoint method to exhibit the expected behavior, the object or element located at position (x, y) must support and respond to mouse events.

Example

The following example prompts the user to enter x and y coordinates to specify the location of the element. If an element corresponds to the specified location, the element tag name is displayed. If there is no corresponding element, a message is displayed to the user.

Sub GetElement()
'Returns an HTML element that corresponds to a set of coordinates

    Dim objApp As FrontPage.Application
    Dim objDoc As DispFPHTMLDocument
    Dim objElement As IHTMLElement
    Dim lngX As Long
    Dim lngY As Long

    Set objApp = FrontPage.Application
    Set objDoc = objApp.ActiveDocument
    'Prompt user for coordinates.
    lngX = InputBox("Enter the X position of the element you want to select.")
    lngY = InputBox("Enter the Y position of the element you want to select.")
    'Get the element based on the user's coordinates.
    Set objElement = objDoc.elementFromPoint(lngX, lngY)

    'If the search was succesful, display message
    If objElement Is Nothing Then
        MsgBox "The specified coordinates did not return an element."
    Else
        'Otherwise display message
        MsgBox "The element is of type " & objElement.tagName & "."
    End If

End Sub