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:

  1. Option Explicit
  2. Sub AddMacrotoShape()
  3. ''
  4. ActiveSheet.Shapes("Rectangle 1").OnAction = "GenerateReport"
  5. ''
  6. End Sub

Description:

a) OnAction method is used to assign a macro to shape.

 

You can find similar Excel Questions and Answer hereunder

1) How do i put double quotes in a string in vba in Excel

2) How can I shade alternate rows in color using VBA to make it easier to read voluminous data running into hundreds of rows?

3) How to delete rows with Excel VBA

4) How can I extract file name from a full path including folder path and file name?

5) Excel 2010 vba replacement of application filesearch in Excel

6) Here a explanation about the global seek function in VBA. Goal Seek is another tool under What If analysis that does a unique function as Scenario Manager.

7) How can I get users to select a file for processing using my macro?

8) Tables in Excel VBA. How you can create table in VBA and work with them with macros

9) How do I update my DropDown list whenever the sheet is activated?

10) How can worksheet functions be accessed in VBA?

 

Here the previous and next chapter