Adding PowerPoint animations via vbscript always results in “Custom” animation

好久不见. 提交于 2019-12-11 09:19:09

问题


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

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.

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:

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.


回答1:


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

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).

This would lead to the following change:

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


来源:https://stackoverflow.com/questions/42548158/adding-powerpoint-animations-via-vbscript-always-results-in-custom-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!