Active Member
February 12, 2020
Can anyone help me with this?
I have a big shape object embedded in my worksheet, which covers many cells below it. The shape has been filled with color and its transparency has been set to 75%.
I want to write an even procedure for mouse left click (if not possible double click). i.e., if I double click within any specific point of the shape, then the system should select the exact cell reference and return it instead of choosing the shape object. Further, it should choose the precise cell right below the mouse click.
Thanks in advance.
Trusted Members
Moderators
November 1, 2018
Unfortunately, the Window.RangeFromPoint method seems to return the shape rather than the range underneath but if you can work with a slightly hacky workaround, you can do it by assigning this ShapeClick macro to the shape, which hides the shape temporarily then schedules a routine to run immediately that can affect the correct range and re-show the shape:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim sh As Shape
Sub ShapeClick()
Set sh = ActiveSheet.Shapes(Application.Caller)
sh.Visible = False
Application.OnTime Now(), "getrange"
End Sub
Sub GetRange()
Dim cursorWhere As POINTAPI
Dim selected As Object
If GetCursorPos(cursorWhere) <> 0 Then
DoEvents
Set selected = ActiveWindow.RangeFromPoint(cursorWhere.x, cursorWhere.y)
If TypeName(selected) = "Range" Then selected.Interior.Color = vbRed
sh.Visible = True
End If
End Sub
Active Member
February 12, 2020
Hi Phil
We have a BBS system wherein several shape objects have to be embedded in one or multiple cells. if it is covering a single cell, I thought of writing cell value as the name of the shape and accordingly choose the right formula and process accordingly. However, if the shape covers multiple cells there comes a challenge! Hence, if I have this solution then whether a single cell or multiple cells I can apply based on mouse click.
This requirement just came from our team and I still struggle to get the logic to start with the development....
when I have seen the cursor's column and row highlight solution provided in this site, I have seen a comment that does not fill the shape as you cannot select the cell below. I wonder if you have any solution to overcome so that I can use similar logic for my requirement.
Note: By the way, your VBA solution for cursor highlights is very good using shape. I also found a software called Kutools which is not using shapes not using a conditional format, appears like a cell format but while not disturbing original cell formats it also works even on a protected sheet with an unknown password... I am totally clueless about how they could have developed!
Thanks
Active Member
February 12, 2020
Hi Phil
As I mentioned, I yet to start this development. Meanwhile, I got some glimmer of hope at the below site...will look into it.
https://stackoverflow.com/ques.....6#60205296
Thanks,
regards
Duraivel S
October 5, 2010
Hi Duraivel,
I like to make things as simple as possible. I've often found that 'requirements' for a job are actually focussed on how to do something rather than the end result.
So by saying something must be done in a particular way, rather than saying this is the result we want, the poor old developer (you and me) end up jumping through very complicated programming hoops to deliver what the 'requirements' asked for 🙂
Anyway, best of luck with the project.
Phil
1 Guest(s)