2017-03-02 30 views
1

使用vbscript我試圖自動創建PowerPoint演示文稿。其原因是我有一個文件夾中有幾十個PNG圖像,我需要在相同的位置插入同一張幻燈片。它們都是透明的,形成一個大的圖像。但是,我需要一個接一個地展示整個圖像。因此,而不是做手工,我想出了下面的VBScript:通過vbscript添加PowerPoint動畫總是導致「自定義」動畫

Set powerPointApp = CreateObject("PowerPoint.Application") 
Set fileSystem = CreateObject("Scripting.FileSystemObject") 
Set presentation = powerPointApp.Presentations.Add() 

presentation.PageSetup.SlideSize  = 15 '15 is the enum value of the enum for 16:9, see http://stackoverflow.com/questions/21598090/how-to-change-powerpoint-pictures-in-widescreen-format 
presentation.PageSetup.FirstSlideNumber = 1 
presentation.PageSetup.NotesOrientation = msoOrientationHorizontal 

Set presentationSlide = presentation.Slides.Add(1, 12) 

For Each file In fileSystem.GetFolder("C:\Temp\Images").Files 
    If InStr(1, file.Name, "Partial_Image", 1) = 1 Then 
    Set picture = presentationSlide.shapes.AddPicture(file.path, True, True, 0, 0) 
    Set effect = presentationSlide.TimeLine.MainSequence.AddEffect(picture, msoAnimEffectFade) 
    'Set effect = presentationSlide.TimeLine.MainSequence.AddEffect(picture, msoAnimEffectFade, msoAnimationLevelNone, msoAnimTriggerAfterPrevious, -1) 
    End if 
Next 

presentation.SaveAs("C:\Temp\test.pptx") 
presentation.Close 
powerPointApp.Quit 

所以,當我運行該腳本將打開PowerPoint,創建一個新的PowerPoint演示文稿,更改它的設置並添加新的幻燈片。然後它遍歷C:\ Temp \ Images中的文件,如果它在文件名中找到包含「Partial_Image」的圖像,則將該圖像插入到新幻燈片中。此過濾是必要的,因爲該文件夾包含我不想插入的文件。之後,它會爲每個插入的圖像添加「淡入淡出」入口動畫。

現在有趣的部分是,這實際上工作,即我結束了一個新的PowerPoint演示文稿,確實有動畫圖像裏面。然而,而不是顯示每個圖像使用「漸變」高考動畫,它只是讓我發現,它使用「自定義」高考動畫:

enter image description here

所以,不管我怎麼變的語句來插入動畫(「AddEffect」調用)我總是以「自定義」結束,而不是實際定位的動畫。最後的動畫工作,即我得到所需的效果,但它只是告訴我,這是一個自定義動畫。有誰知道爲什麼會出現這種情況?實際看到使用的動畫類型將會很有幫助。

回答

1

看來你的上下文不知道枚舉值msoAnimEffectFade並回落到默認值。

您是否知道您也可以使用您想要使用的枚舉值int。在你的情況下,這將是10(見MSDN)。

這將導致以下變化:

Set effect = presentationSlide.TimeLine.MainSequence.AddEffect(picture, 10) 
+1

這個工程,動畫正確設置爲「變臉」的方式。謝謝! – ackh