vba add shape to worksheet in Excel

Q188. In Excel, how do I add a shape using VBA?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub AddShapes()
  3. ''
  4. 'Add a Rectangle.
  5. ActiveSheet.Shapes.AddShape msoShapeRectangle, 20, 20, 50, 50
  6. ''
  7. 'Add a Rounded Rectangle.
  8. ActiveSheet.Shapes.AddShape msoShapeRoundedRectangle, 20, 120, 50, 50
  9. ''
  10. 'Add a 4-point star.
  11. ActiveSheet.Shapes.AddShape msoShape4pointStar, 20, 220, 50, 50
  12. ''
  13. End Sub


a) Line 5, 8, 11 - the 4 numbered arguments after the Shape type are as follows -

1) Position of Shape from Left Edge of the WorkSheet

2) Position of Shape from Top Edge of the WorkSheet

3) Shape Width

4) Shape Height

b) For getting supported Shape Types, consult MSDN, potential source -

Result after Macro execution:

excel vba add shape to worksheet


You can find similar Excel Questions and Answer hereunder

1) How can I hide all comments in my WorkSheet using VBA?

2) How can I dynamically add series to an existing chart using VBA?

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

4) Every time I make an update to my Worksheet, I would like to add a timestamp to my Last Updated field. In Excel, how can I do that in Worksheet?

5) Vba length of an array in Excel

6) Vba to return week numbers in Excel

7) How can I get users to select a folder to save the output of my macro?

8) How can I hide a specific Shape in my WorkSheet?

9) How can I add a WorkSheet and name it as required using VBA?

10) How can I set non-contiguous print area using VBA?

11) How can I identify all cells with Conditional Formatting in my WorkSheet?

12) How can I add a background image to a worksheet?

13) How do I add a symbol like Triangle / Inverted Triangle for indicating trends in a cell using VBA?

14) How can I identify all cells with Data Validation in my WorkSheet?

15) How do I restrict user entry in ActiveX Text Box to just numeric values?