vba assign macro to shape in Excel
Q189. In Excel, how do I assign a macro to a shape using VBA?
For example, I have a macro "GenerateReport" in my WorkBook. I want to assign a macro to Shape "Rectangle 1" using VBA.
To do it in Excel, here is the answer:
- Option Explicit
- Sub AddMacrotoShape()
- ActiveSheet.Shapes("Rectangle 1").OnAction = "GenerateReport"
- End Sub
a) OnAction method is used to assign a macro to shape.