Share via

Drawing Shapes using VBA/Macros

Anonymous
2011-01-29T16:50:25+00:00

Dear all

I have a query which I hope somebody would solve.

I have a project where I need to  create shapes like say an ellipse or a sine curve or somewhat slightly complicated curves. I understand that part of what I want can be solved using charts but they are a bit too rigid to solve my problem.

Hence, I request u to please give me the code to draw a simple rectangle using macro. For eg. i have 4 points (1,1), (1,0), (0,1) and (0,0). Please tell me how I create these 4 points in excel and how to write code to join these points by a line (in my case, i need to generate a curve). Based on the code that is given, I can try to generate a curve or if I cant, I will get back to you.

For now, plzz give me relevant code. Thanks in advance.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-01-30T13:53:44+00:00

Here is some code to draw a simple rectangle.  The 4 points are defined relative to the cell boundries:

Sub PlaceRectangle()

' 0,0 is upper left corner of A1

' 0,1 is upper left corner of B1

' 1,0 is upper left corner of A2

' 1,1 is upper left corner of B2

With Range("A1")

    le = .Left

    tp = .Top

    wd = .Offset(0, 1).Left - le

    he = .Offset(1, 0).Top - tp

End With

With ActiveSheet

.Shapes.AddShape(msoShapeRectangle, le, tp, wd, he).Select

End With

End Sub


gsnu201101

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2011-01-29T17:13:33+00:00

    (Also asked in the Microsoft Office Customization and Programming forum)

    Not exactly what you ask, but hopefully you can use it: http://www.jkp-ads.com/Articles/ChartAnEquation00.asp

    Was this answer helpful?

    0 comments No comments