简体   繁体   English

VBA PowerPoint 2016 形状 BuildFreeform 属性 after.ConvertToShape

[英]VBA PowerPoint 2016 shapes BuildFreeform properties after .ConvertToShape

After creating a shape with.ConvertToShape, what is its index in Shapes?用.ConvertToShape 创建形状后,它在Shapes 中的索引是多少? And how do I give it a Line colour?我如何给它一个线条颜色? I want to create several msoFreeform shapes, and give them different colours.我想创建几个 msoFreeform 形状,并赋予它们不同的颜色。 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.谢谢你的帮助。

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.在任何情况下,.ConvertToShape 返回对新创建形状的引用,因此您可以立即使用该引用来设置颜色或您喜欢的任何属性。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM