RangeFromPoint Only Finds ShapesAt 0, 0 coordinates
What I mean by "correct" result is that the return value of RangeFromPoint is not "Nothing" even though a Shape was not found. Instead the return value is a Range which address is nowhere near the address of the shape that I am trying to delete
Here is the code
Sub A(
Dim CellPointsX As Long, CellPointsY As Long, CellPixelsX As Long, CellPixelsY As Long,
ScrollRowPoints As Long, ScrollColPoints As Long, ScrollPixelsX As Long, ScrollPixelsY As Long,
WndPointsX As Long, WndPointsY As Long, WndPixelsX As Long, WndPixelsY As Long,
AppPointsX As Long, AppPointsY As Long, AppPixelsX As Long, AppPixelsY As Long,
Result As Variant, ResultPixelsX As Long, ResultPixelsY As Long, AllShapes As ShapeRang
With ActiveWindo
CellPointsX = ActiveCell.Lef
CellPointsY = ActiveCell.To
CellPixelsX = .PointsToScreenPixelsX(CellPointsX
CellPixelsY = .PointsToScreenPixelsY(CellPointsY
WndPointsX = .Lef
WndPointsY = .To
WndPixelsX = .PointsToScreenPixelsX(WndPointsX
WndPixelsY = .PointsToScreenPixelsY(WndPointsY
ScrollColPoints = ActiveSheet.Cells(.ScrollRow, .ScrollColumn).Lef
ScrollRowPoints = ActiveSheet.Cells(.ScrollRow, .ScrollColumn).To
ScrollPixelsX = .PointsToScreenPixelsX(ScrollColPoints
ScrollPixelsY = .PointsToScreenPixelsY(ScrollRowPoints
AppPointsX = Application.Lef
AppPointsY = Application.To
AppPixelsX = .PointsToScreenPixelsX(Application.Left
AppPixelsY = .PointsToScreenPixelsY(Application.Top
Set Result = .RangeFromPoint(x:=CellPixelsX, y:=CellPixelsY
End Wit
If Result Is Nothing The
MsgBox "Result Is Nothing." & Chr(13)
& "CellPointsX = " & Str(CellPointsX) & " CellPointsY = " & Str(CellPointsY) & Chr(13)
& "CellPixelsX = " & Str(CellPixelsX) & " CellPixelsY = " & Str(CellPixelsY) & Chr(13)
& "WndPointsX = " & Str(WndPointsX) & " WndPointsY = " & Str(WndPointsY) & Chr(13)
& "WndPixelsX = " & Str(WndPixelsX) & " WndPixelsY = " & Str(WndPixelsY) & Chr(13)
& "AppPointsX = " & Str(AppPointsX) & " AppPointsY = " & Str(AppPointsY) & Chr(13)
& "AppPixelsX = " & Str(AppPixelsX) & " AppPixelsY = " & Str(AppPixelsY) & Chr(13)
& "ScrollColPoints = " & Str(ScrollColPoints) & " ScrollRowPoints = " & Str(ScrollRowPoints) & Chr(13)
& "ScrollPixelsX = " & Str(ScrollPixelsX) & " ScrollPixelsY = " & Str(ScrollPixelsY
Els
If TypeName(Result) = "Range" The
Result.Selec
ResultPixelsX = ActiveWindow.PointsToScreenPixelsX(Result.Left
ResultPixelsY = ActiveWindow.PointsToScreenPixelsY(Result.Top
MsgBox "Result.Address = " & Result.Address & Chr(13)
& "ResultPointsX = " & Str(Result.Left) & " ResultPointsY = " & Str(Result.Top) & Chr(13)
& "ResultPixelsX = " & Str(ResultPixelsX) & " ResultPixelsY = " & Str(ResultPixelsY) & Chr(13)
& "CellPointsX = " & Str(CellPointsX) & " CellPointsY = " & Str(CellPointsY) & Chr(13)
& "CellPixelsX = " & Str(CellPixelsX) & " CellPixelsY = " & Str(CellPixelsY) & Chr(13)
& "WndPointsX = " & Str(WndPointsX) & " WndPointsY = " & Str(WndPointsY) & Chr(13)
& "WndPixelsX = " & Str(WndPixelsX) & " WndPixelsY = " & Str(WndPixelsY) & Chr(13)
& "AppPointsX = " & Str(AppPointsX) & " AppPointsY = " & Str(AppPointsY) & Chr(13)
& "AppPixelsX = " & Str(AppPixelsX) & " AppPixelsY = " & Str(AppPixelsY) & Chr(13)
& "ScrollColPoints = " & Str(ScrollColPoints) & " ScrollRowPoints = " & Str(ScrollRowPoints) & Chr(13)
& "ScrollPixelsX = " & Str(ScrollPixelsX) & " ScrollPixelsY = " & Str(ScrollPixelsY
Els
Result.Selec
MsgBox "Result Is Picture. TopLeftCell.Address = " & Result.TopLeftCell.Address & Chr(13)
& "ResultPointsX = " & Str(Result.Left) & " ResultPointsY = " & Str(Result.Top) & Chr(13)
& "ResultPixelsX = " & Str(ActiveWindow.PointsToScreenPixelsX(Result.Left )) & " ResultPixelsY = "
& Str(ActiveWindow.PointsToScreenPixelsY(Result.Top) ) & Chr(13)
& "CellPointsX = " & Str(CellPointsX) & " CellPointsY = " & Str(CellPointsY) & Chr(13) _
& "CellPixelsX = " & Str(CellPixelsX) & " CellPixelsY = " & Str(CellPixelsY) & Chr(13) _
& "WndPointsX = " & Str(WndPointsX) & " WndPointsY = " & Str(WndPointsY) & Chr(13) _
& "WndPixelsX = " & Str(WndPixelsX) & " WndPixelsY = " & Str(WndPixelsY) & Chr(13) _
& "AppPointsX = " & Str(AppPointsX) & " AppPointsY = " & Str(AppPointsY) & Chr(13) _
& "AppPixelsX = " & Str(AppPixelsX) & " AppPixelsY = " & Str(AppPixelsY) & Chr(13) _
& "ScrollColPoints = " & Str(ScrollColPoints) & " ScrollRowPoints = " & Str(ScrollRowPoints) & Chr(13) _
& "ScrollPixelsX = " & Str(ScrollPixelsX) & " ScrollPixelsY= " & Str(ScrollPixelsY)
End If
End If
End Sub
|