只好采用笨办法了,虽然有点慢,可以实现目的,但不一定是最佳方案. 本示例可以找到选择的单元格的相对于屏幕的坐标区域,亦即像素区域. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Type POINTAPI x As Long y As Long End Type Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Dim lngCurPos As POINTAPI
Dim mTop As Long, mLeft As Long, mRight As Long, mBottom As Long
Dim x1 As Long, y1 As Long, x2 As Long, y2 As Long GetCursorPos lngCurPos
For y = lngCurPos.y To 0 Step -1
If ActiveWindow.RangeFromPoint(lngCurPos.x, y).Address <> Target.Address Then
mTop = y - 1
Exit For
End If
Next y
For y1 = lngCurPos.y To 768
If ActiveWindow.RangeFromPoint(lngCurPos.x, y1).Address <> Target.Address Then
mBottom = y1 - 1
Exit For
End If
Next y1
For x = lngCurPos.x To 0 Step -1
If ActiveWindow.RangeFromPoint(x, lngCurPos.y).Address <> Target.Address Then
mLeft = x - 1
Exit For
End If
Next x
For x1 = lngCurPos.x To 1024
If ActiveWindow.RangeFromPoint(x1, lngCurPos.y).Address <> Target.Address Then
mRight = x1 - 1
Exit For
End If
Next x1 [A1] = mTop [A2] = mLeft
[A3] = mRight [A4] = mBottom End Sub |