ROCA
ROCA

Reputation: 149

Select an object by clicking it

I have a macro that changes colour of shapes on worksheet on clicking a specific shape.

However, when I click this shape it doesn´t really select it, so I cannot differ this "clicked image" from the others, because clicking doesn´t select the shape.

How can I select the shape by clicking it executing a macro at the same time?

I need to execute this macro:

For Each shp In ActiveSheet.Shapes
shp.Fill.ForeColor.RGB = RGB(255, 255, 255)
shp.Line.ForeColor.RGB = RGB(138, 206, 174)
shp.Line.Weight = 1
End If
Next

...and the clicked shape needs to be changed as such:

With Selection.ShapeRange
.Fill.ForeColor.RGB = RGB(208, 209, 208)
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.Weight = 6

Upvotes: 0

Views: 50

Answers (1)

Tim Williams
Tim Williams

Reputation: 166381

Look at using Application.Caller - inside a method called from a click on a shape, this will give you the name of the clicked shape.

So something like:

Dim shp As Shape
Set shp = ActiveSheet.Shapes(Application.Caller) 

should give you the clicked-on shape.

Upvotes: 1

Related Questions