簡體   English   中英

VBA PowerPoint 2016 形狀 BuildFreeform 屬性 after.ConvertToShape

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

用.ConvertToShape 創建形狀后,它在Shapes 中的索引是多少? 我如何給它一個線條顏色? 我想創建幾個 msoFreeform 形狀,並賦予它們不同的顏色。 我已經走到這一步了:

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

我想給創建的自由形式一個顏色,然后創建另一個自由形式並給它另一種顏色,等等,對於幾個自由形式。 謝謝你的幫助。

作為一般規則,提供一個獨立運行的示例是個好主意,這樣任何想要幫助的人都可以從簡單的復制/粘貼開始,而不必修改您的代碼。

在任何情況下,.ConvertToShape 返回對新創建形狀的引用,因此您可以立即使用該引用來設置顏色或您喜歡的任何屬性。 在這里,我只是獲取新形狀的名稱並將其顯示在消息框中:

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