通过 vbscript 添加 PowerPoint 动画总是会导致“自定义"动画片 [英] Adding PowerPoint animations via vbscript always results in "Custom" animation

查看:38
本文介绍了通过 vbscript 添加 PowerPoint 动画总是会导致“自定义"动画片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using vbscript I'm attempting to automate the creation of a PowerPoint presentation. The reason for it is that I have a folder with several dozens of png images which I need to insert into the same slide at the same position. They're all transparent and form one large image. However, I need to show one after the other until the full image is revealed. So instead of doing it by hand I came up with the following 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"的图像,则将该图像插入到新幻灯片中.这种过滤是必要的,因为文件夹包含我不想插入的文件.之后,它会为插入的每个图像添加淡入淡出"入口动画.

So, when I run the script it will open PowerPoint, create a new PowerPoint presentation, change the settings of it and add a new slide. It then iterates through the files in C:\Temp\Images and if it finds an image containing "Partial_Image" in the file name it inserts that image into the new slide. This filtering is necessary because the folder contains files that I do not want to insert. After that it adds the "Fade" entrance animation to every image that is inserted.

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

Now the interesting part is that this actually works, i.e. I end up with a new PowerPoint presentation that indeed has the animated images inside. However, instead of showing that each image uses the "Fade" entrance animation it just shows me that it uses the "Custom" entrance animation:

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

So, no matter how I change the statement to insert the animation ("AddEffect" call) I always end up with "Custom" instead of the animation that I actually target. The animation in the end works, i.e. I get the desired effect but it just tells me that it is a custom animation. Does anyone know why this is the case? It would be helpful to actually see the type of animation that is used.

推荐答案

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

It seems your context doesn't know the enum value msoAnimEffectFade and falls back to the default value.

您是否知道您还可以使用要使用的枚举的 int 值.在您的情况下,这将是 10(请参阅 MSDN).

May you know you can also use the int value of the enum you want to use. In your case this would be 10 (See MSDN).

这将导致以下变化:

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

这篇关于通过 vbscript 添加 PowerPoint 动画总是会导致“自定义"动画片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆