Drawing a Curve programmatically

N

Nichevo

Hiya

I'm trying to draw around a circle using a freeform drawing but I can seem to figure out the drawing of the curve - This is what I have so far:

Sub Macro8()
Set ws = ThisWorkbook.Worksheet("Sheet1")
x = 1200
y = 100
SV = 100
'Draws the Circle
With ws.Shapes.AddShape(msoShapeOval, x, y, SV, SV)
.Fill.ForeColor.SchemeColor = 2
.Line.Visible = msoFalse
End With
'Draws the Segement of the Circle
With ws.Shapes.BuildFreeform(msoEditingAuto, x + SV / 2, y)
.AddNodes msoSegmentLine, msoEditingAuto, x + SV / 2, y + SV / 2
.AddNodes msoSegmentLine, msoEditingAuto, x, y + SV / 2
'Part of the program I'm struggling with
.AddNodes msoSegmentLinem, msoEditingCorner, x + SV / 4, y + SV / 4, x + (SV / 4) * 2, y + (SV / 4) * 2, x + SV / 2, y
.ConvertToShape.Select
End With
End Sub

The part I'm having trouble with is
..AddNodes msoSegmentLinem, msoEditingCorner, x + SV / 4, y + SV / 4, x + (SV / 4) * 2, y + (SV / 4) * 2, x + SV / 2, y
I can draw a straight line back but I want to make it curved and it keeps bringing up and error about a value being out of range when I get to this line - anyone have any ideas.
 
P

Patrick Molloy

one typo and change msoSegmentLINE to msoSegmentCurve

This tested OK:

Sub Macro8()
Dim WS As Worksheet
Dim X As Long
Dim y As Long
Dim SV As Long

Set WS = ThisWorkbook.Worksheets("Sheet1")
X = 1200
y = 100
SV = 100
'Draws the Circle
With WS.Shapes.AddShape(msoShapeOval, X, y, SV, SV)
.Fill.ForeColor.SchemeColor = 2
.Line.Visible = msoFalse
End With
'Draws the Segement of the Circle
With WS.Shapes.BuildFreeform(msoEditingAuto, X + SV / 2,
y)
.AddNodes msoSegmentLine, msoEditingAuto, X + SV / 2,
y + SV / 2
.AddNodes msoSegmentLine, msoEditingAuto, X, y + SV /
2
'Part of the program I'm struggling with
.AddNodes msoSegmentCurve, msoEditingCorner, X + SV /
4, y + SV / 4, X + (SV / 4) * 2, y + (SV / 4) * 2, X +
SV / 2, y
.ConvertToShape.Select
End With
End Sub

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Hiya

I'm trying to draw around a circle using a freeform
drawing but I can seem to figure out the drawing of the
curve - This is what I have so far:
Sub Macro8()
Set ws = ThisWorkbook.Worksheet("Sheet1")
x = 1200
y = 100
SV = 100
'Draws the Circle
With ws.Shapes.AddShape(msoShapeOval, x, y, SV, SV)
.Fill.ForeColor.SchemeColor = 2
.Line.Visible = msoFalse
End With
'Draws the Segement of the Circle
With ws.Shapes.BuildFreeform(msoEditingAuto, x + SV / 2, y)
.AddNodes msoSegmentLine, msoEditingAuto, x + SV / 2, y + SV / 2
.AddNodes msoSegmentLine, msoEditingAuto, x, y + SV / 2
'Part of the program I'm struggling with
.AddNodes msoSegmentLinem, msoEditingCorner, x +
SV / 4, y + SV / 4, x + (SV / 4) * 2, y + (SV / 4) * 2, x
+ SV / 2, y
.ConvertToShape.Select
End With
End Sub

The part I'm having trouble with is
..AddNodes msoSegmentLinem, msoEditingCorner, x + SV /
4, y + SV / 4, x + (SV / 4) * 2, y + (SV / 4) * 2, x +
SV / 2, y
I can draw a straight line back but I want to make it
curved and it keeps bringing up and error about a value
being out of range when I get to this line - anyone have
any ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top