Insert a shape in excel vba

Riccardo Giovinazzi 1 Reputation point
2022-10-07T16:15:06.2+00:00

Hello everybody,
I am new in vba and would like to know how can i create three different rectangles in excel giving to different celles the x and y position of the origin of every shape, as well as the width and height of each rectangle.

Thank you to whoever may help.

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dillon Silzer 60,736 Reputation points Volunteer Moderator
    2022-10-07T16:25:48.567+00:00

    Hi @Riccardo Giovinazzi

    You can create rectangles with the .addshape method. For simplicity, I created a macro called test():

    248539-image.png

    Cited from https://learn.microsoft.com/en-us/office/vba/api/excel.shapes.addshape

    Set myDocument = Worksheets(1)   
    myDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200  
    

    248611-image.png

    ---------------------------------

    If this is helpful please accept answer.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.