2017-08-15 125 views
0

我试图在PowerPoint中创建,每个重复对象与比下一个稍短的运动路径,像这样的一排复制的运动路径的长度:增量使用VBA

First Image

我知道你不能在VBA从头开始添加路径动画,所以我用VBA复制和粘贴的对象和它的运动轨迹,然后编辑运动路径。

这是我的VBA代码: 子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 

但是,输出是这样的: Second Image

+0

我什么都不知道关于PowerPoint中VBA,但如果我不得不猜测,我会尝试...' “M 0 0 L 0” 和(X * 0.7)' – braX

回答

0

是的,我知道,我试图给一个变量插入到串。是这样做的正确的方法是"M 0 0 L 0 " & (x * 0.7)

谢谢@braX的运动路径

0

路径属性,它代表了VML字符串。 VML的字符串是一条线或贝塞尔曲线(用于 PowerPoint演示目的)坐标的集合。 的值是滑动的尺寸级分。

您可以生成使用此功能递增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