I came back with a far more rocky situation.
I need to make a shape "click through" which mean noone can select it, and I can select the cell on the back of it.
So i wrote below function that return the right cell
Function ShapeOnClick() As Excel.Range
'Created by HvSum
Dim Rng As Range, DShape As Shape
Dim X As Long, Y As Long, Zoom As Byte
Zoom = Int(ActiveWindow.Zoom)
With ActiveSheet
X = 0.75 * (MouseX() - Split(getCellLocation(.Range("A1")), ",")(0))
If ActiveWindow.SplitColumn > 0 Then X = X - .Columns(ActiveWindow.SplitColumn + 1).left
Y = 0.75 * (MouseY() - Split(getCellLocation(.Range("A1")), ",")(1))
If ActiveWindow.SplitRow > 0 Then Y = Y - .Rows(ActiveWindow.SplitRow + 1).top
x = x / Zoom * 100
y = y / Zoom * 100
Set DShape = .Shapes.AddShape(msoLine, X, Y, 1, 1)
End With
With DShape
.Visible = msoTrue
Set Rng = .TopLeftCell
.Delete
End With
Set ShapeOnClick = Rng
End Function
Explain: MouseX, mouseY are functions getting mouse position from API call.
Getcelllocation is a function use to get the X, Y coor on screen which using ActiveWindow.PointsToScreenPixelsX and ActiveWindow.PointsToScreenPixelsY build-in function to convert points of 1st cell of usable screen to X, Y coor on screen.
0.75 is a normal const use as convert rate between pixel and point (office).
everything work very well until I test with freezing panel (split row/split column) from that moment, every click on a shape alway wrong, lead to nearby cell...
Can anyone point out what is wrong ?
Well, after very detail test the scale and DPI, I figured out only zoom mod 25 = 0 work. Here is the final code for determine Cell on Screen X Y coordinates
For anytime, when you want to know which range behind your mouse, call the function, it'll return exactly range at your mouse's pointer.
Hope everyone could find it usefull and vote for me. Have nice day ;)