편집

다음을 통해 공유


Window.RangeFromPoint method (Excel)

Returns the Shape or Range object that is positioned at the specified pair of screen coordinates. If there isn't a shape located at the specified coordinates, this method returns Nothing.

Syntax

expression.RangeFromPoint (x, y)

expression A variable that represents a Window object.

Parameters

Name Required/Optional Data type Description
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.

Return value

Object

Example

This example returns the alternative text for the shape immediately below the mouse pointer if the shape is a chart, line, or picture.

Private Function AltText(ByVal intMouseX As Integer, _ 
 ByVal intMouseY as Integer) As String 
 Set objShape = ActiveWindow.RangeFromPoint _ 
 (x:=intMouseX, y:=intMouseY) 
 If Not objShape Is Nothing Then 
 With objShape 
 Select Case .Type 
 Case msoChart, msoLine, msoPicture: 
 AltText = .AlternativeText 
 Case Else: 
 AltText = "" 
 End Select 
 End With 
 Else 
 AltText = "" 
 End If 
End Function

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.