首页 文章

通过vbscript添加PowerPoint动画始终会生成“自定义”动画

提问于
浏览
1

使用vbscript我试图自动创建PowerPoint演示文稿 . 原因是我有一个包含几十个png图像的文件夹,我需要将它们插入同一位置的同一张幻灯片中 . 它们都是透明的,形成一个大图像 . 但是,我需要一个接一个地显示,直到显示完整的图像 . 所以不是手工完成,而是想出了以下的vbscript:

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”的图像,则会将该图像插入到新幻灯片中 . 此过滤是必要的,因为该文件夹包含我不想插入的文件 . 之后,它将“Fade”入口动画添加到每个插入的图像 .

现在有趣的是,这实际上是有效的,即我最终得到一个新的PowerPoint演示文稿,其中确实有内部的动画图像 . 但是,不是显示每个图像使用“淡入淡出”入口动画,而是只显示它使用“自定义”入口动画:

enter image description here

所以,无论我如何更改语句以插入动画(“AddEffect”调用),我总是以“自定义”而不是我实际定位的动画结束 . 最后的动画工作,即我得到了所需的效果,但它只是告诉我它是一个自定义动画 . 有谁知道为什么会这样?实际看到使用的动画类型会很有帮助 .

1 回答

  • 1

    您的上下文似乎不知道枚举值 msoAnimEffectFade 并回退到默认值 .

    您是否知道也可以使用要使用的枚举的 int 值 . 在你的情况下,这将是 10 (见MSDN) .

    这将导致以下变化:

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

相关问题