Link to home
Create AccountLog in
Avatar of Saqib Husain
Saqib HusainFlag for Pakistan

asked on

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
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Your horizontal positions are off the sheet.

Kevin
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
Avatar of Saqib Husain

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ssagibh:

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

Jaes