0

After creating a shape with .ConvertToShape, what is its index in Shapes? And how do I give it a Line colour? I want to create several msoFreeform shapes, and give them different colours. I have come this far:

With myDocument.Shapes.BuildFreeform(EditingType:=msoEditingCorner, X1:=X(1), Y1:=Y(1))
    For i = 1 To 361
    .AddNodes SegmentType:=msoSegmentLine, EditingType:=msoEditingAuto, X1:=X(i), Y1:=Y(i)
    Next i
    .ConvertToShape
End With

For Each shp In ActivePresentation.Slides(1).Shapes
    If shp.Type = 5 Then 'msoFreeform
    shp.Line.ForeColor.RGB = RGB(0, 0, 64) 'this will however colour all in the same colour
    shp.Line.Weight = 2.5
    End If
    Debug.Print shp.Type
Next shp

I would like to give a colour to the freeform created, then create another freeform and give it another colour, and so on, for several freeforms. Thanks for any help.

user6439024
  • 79
  • 1
  • 1
  • 8
  • What does your comment mean "this will however colour all in the same colour"? Are you expecting the shape outline to be in more than one color? Or do you mean all shapes get the same outline? – John Korchok Jul 13 '20 at 17:49
  • I realise that it is not possible to get different colours in one shape. I should at least try to get different colours for each shape. – user6439024 Jul 14 '20 at 04:55

1 Answers1

1

As a general rule, it's a good idea to provide an example that runs on its own, so that anyone who'd like to help can start with a simple copy/paste rather than having to adapt your code.

In any case, .ConvertToShape returns a reference to the newly created shape, so you can immediately use that reference to set color or whatever properties you like. Here I'm just grabbing the new shape's name and displaying it in a messagebox:

Sub TryThis()

Dim oSh As Shape
Dim i As Long

With ActivePresentation.Slides(1).Shapes.BuildFreeform(EditingType:=msoEditingCorner, X1:=x(1), Y1:=y(1))
    For i = 1 To 361
    .AddNodes SegmentType:=msoSegmentLine, EditingType:=msoEditingAuto, X1:=x(i), Y1:=y(i)
    Next i
    Set oSh = .ConvertToShape
    MsgBox oSh.Name
    
End With

End Sub
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • Steve's answer is precisely what I was looking for. Until then, I wrote the following. k = ActivePresentation.Slides(1).Shapes.Count With ActivePresentation.Slides(1).Shapes(k) .Line.ForeColor.RGB = RGB(255 - 32 * n, 0 + 32 * n, 192) .Line.ForeColor.RGB = RGB(255 * Rnd(), 255 * Rnd(), 255 * Rnd()) .Line.Weight = 2 .Fill.Transparency = 1 End With (I don't know how to format this as code.) – user6439024 Jul 16 '20 at 14:33