2017-08-15 47 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