使用 VBA 递增复制的运动路径的长度



我正在尝试在PowerPoint中创建一行重复的对象,每个对象的运动路径都比下一个略短,如下所示:

第一张图片

我知道您无法在 VBA 中从头开始添加路径动画,因此我使用 VBA 复制并粘贴对象及其运动路径,然后编辑运动路径。

这是我的 VBA 代码: Sub CopyPastePosition((

' Copy the shape in slide 2 which has a custom motion path aleady
ActivePresentation.Slides(2).Shapes(3).Copy
Dim x As Integer
' For loop - create 5 duplicates
For x = 1 To 5
' Each duplicate is nudged to the left by x*100
With ActivePresentation.Slides(1).Shapes.Paste
.Name = "Smiley"
.Left = x * 100
.Top = 1
End With
' This is where I am unsure - I want the motion path to be longer by x amount each time
ActivePresentation.Slides(1).TimeLine.MainSequence(x).Behaviors(1).MotionEffect.Path = "M 0 0 L 0 x*0.7"
Next x
End Sub

但是,输出如下所示: 第二张图片

表示VML 字符串的运动路径的路径属性。VML 字符串是直线或贝塞尔曲线(对于 幻灯片目的(。这些值是幻灯片尺寸的分数。

您可以使用此函数生成递增的 VML 路径。

Function GetPath(MaxSegments As Integer, Increment As Single)
Dim path As String
Dim i As Integer
path = "M 0 0 "
For i = 1 To MaxSegments
path = path & "L 0 " & CStr(Increment * i) & " "
Next
path = path & " E"
GetPath = path
End Function

由于您正在复制/粘贴已经具有运动路径的形状,因此我还将进行此更改以确保我们在粘贴时引用正确的运动路径:

With ActivePresentation.Slides(1).TimeLine
.MainSequence(.MainSequence.Count).Behaviors(1).MotionEffect.path = GetPath(x, 0.7)
End With

是的,我意识到我正在尝试将变量插入字符串中。 是的,正确的方法是"M 0 0 L 0 " & (x * 0.7)

谢谢@braX

最新更新