Drawig Freeform shapes using VBA

I created a Freeform shape while recording a macro. When I try to use that macro I often run into an error depending on the values used.
In the code below I have two parts. The first is the lines recorded and it works fine. The second part is with my values but it gives an error.

Can someone explain the error and propose a remedy?

Saqib

Sub Fform()
    With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 4804.5, 117932.25)
        .AddNodes msoSegmentLine, msoEditingAuto, 4742.25, 117978#
        .AddNodes msoSegmentLine, msoEditingAuto, 4747.5, 118057.5
        .AddNodes msoSegmentLine, msoEditingAuto, 4904.25, 118102.5
        .AddNodes msoSegmentLine, msoEditingAuto, 4956.75, 118044#
        .ConvertToShape.Select
    End With
    With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 6979.297118, 7097.833484)
        .AddNodes msoSegmentLine, msoEditingAuto, 6980.243934, 7097.982595
        .AddNodes msoSegmentLine, msoEditingAuto, 6979.947016, 7095.819007
        .ConvertToShape.Select
    End With
End Sub
LVL 43
Saqib Husain, SyedEngineerAsked:
Who is Participating?
 
zorvek (Kevin Jones)ConsultantCommented:
You're correct. It didn't sound right when I posted it but it was the only thing that made sense.

It looks like the points are too close together. If I move the second one a point to the left or right it works.

Kevin
0
 
zorvek (Kevin Jones)ConsultantCommented:
Your horizontal positions are off the sheet.

Kevin
0
 
zorvek (Kevin Jones)ConsultantCommented:
Nope. I was wrong. The problem is you are using values with too many decimal positions. Cut them down to two decimals or no decimals and you will have better luck.

Kevin
0
 
Saqib Husain, SyedEngineerAuthor Commented:
I dont think so, Kevin.
Try this

    With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 6979.297118, 7097.833484)
        .AddNodes msoSegmentLine, msoEditingAuto, 7980.243934, 7097.982595
        .AddNodes msoSegmentLine, msoEditingAuto, 7979.947016, 7095.819007
        .ConvertToShape.Select
    End With
0
 
LoNeRaVeR9Commented:
ssagibh:

I agree with Kevin.  I played with it a bit and when I moved the nodes farther apart it worked fine.

Jaes
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.