我有一系列从第三方应用程序复制的自由形状。
这些自由形状由开放路径构成,不能在PowerPoint中“组合”(只能组合使用封闭路径制作的自由形式)。
以下宏遍历所选的每个形状,如果它是自由形式,它将创建一个带有闭合路径的副本,然后删除原始形状。
Sub close_poly()
Dim myshp As Shape
Dim mycol As String
Dim mynode As ShapeNode
Dim myxvals As Variant
Dim myyvals As Variant
Dim myxcol As String
Dim myycol As String
Dim myffb As FreeformBuilder
Dim mynewshp As Shape
Dim myname As String
For Each myshp In ActiveWindow.Selection.ShapeRange
With myshp
If .Type = msoFreeform Then
'################ set all line segments to straight
'(makes things easier in my specific case but will not work in many)
nodecount = 1
While nodecount <= .Nodes.Count
.Nodes.SetSegmentType nodecount, msoSegmentLine
nodecount = nodecount + 1
Wend
'############## collect coordinates
myxcol = ""
myycol = ""
For Each mynode In myshp.Nodes
myxcol = myxcol & mynode.Points(1, 1) & ","
myycol = myycol & mynode.Points(1, 2) & ","
Next
myxcol = Left(myxcol, Len(myxcol) - 1)
myycol = Left(myycol, Len(myycol) - 1)
myxvals = Split(myxcol, ",")
myyvals = Split(myycol, ",")
'##############create new freeform
Set myffb = ActiveWindow.View.Slide.Shapes.BuildFreeform(msoEditingAuto, myxvals(0), myyvals(0))
For i = 1 To UBound(myxvals)
myffb.AddNodes msoSegmentLine, msoEditingAuto, myxvals(i), myyvals(i)
Next i
myffb.AddNodes msoSegmentLine, msoEditingAuto, myxvals(0), myyvals(0)
Set mynewshp = myffb.ConvertToShape
myshp.PickUp
mynewshp.Apply
myname = myshp.Name
myshp.Delete
mynewshp.Name = myname
End If
End With
Next myshp
End Sub
问题:有没有更简单的方法来模仿VBA中程序的“关闭路径”功能?
干杯