Vba assign macro to shape in Excel
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.