Forum Discussion
Trying to toggle colour of shapes on mouse click
- Jan 17, 2021
You need only a single macro that you assign to all the shapes:
Sub ChangeFill() With ActiveSheet.Shapes(Application.Caller).Fill .Visible = Not .Visible End With End Sub
Please note that when the interior of a shape is transparent, you'll have to click on its edge to run the macro; clicking inside the shape won't work (precisely because it is transparent).
Wow! Thanks! I'm new to all this (just learning Python as first language and this is my first attempt at VB) and knew there'd be a simple, more elegant solution than my clumsy, long winded one!
Just one problem: I'm getting a run time error on this line: item with specified name not found
With ActiveSheet.Shapes(Application.Caller).Fill
Presumably I need to insert the sheet or workspace in there somewhere? Tell it where to look?
Pity the 'click area' can't be modified, that might be problematic given the small size of some of the shapes, I'm thinking add an extra shape/button off to the side as an undo/clear all feature? More research!
Thanks again, you've been a great help so far 🙂
Make sure that each of your shapes has a unique name.
- nic-nicolJan 17, 2021Copper Contributor
I've got it now!
made a rookie mistake in my haste: hadn't right clicked each shape and assigned it a macro!
That and naming them in the name manager has solved all my problems!
simple but very effective bit of code, you're a genius sir! I'm really grateful!
Later I'll look at a reset shape and maybe making it grey not black, but that's the next stage!
Thanks again!
- nic-nicolJan 17, 2021Copper Contributor
Have set it up with nice fill colours, outline etc, all working perfectly.
only thing is, you mentioned I can't alter the size/position of the click area for each shape, is it possible to make the click area visible?
- HansVogelaarJan 17, 2021MVP
The clickable area of a shape is the visible part:
- If the border is visible, the border is clickable.
- If the border is transparent, it is not clickable.
- If the interior is visible, the interior is clickable.
- If the interior is transparent, it is not clickable.
So what you see is what you get...
- nic-nicolJan 17, 2021Copper Contributor
aren't they assigned a unique name when created? Oval 3, Oval 4, Trapeziod 5, etc?
I've gone into formulas > define name and assigned names but that's not doing anything.