How can I delete all transitions in MS Powerpoint with VBA? - vba

We prepare hundreds of Powerpoint documents per week for use with screen-reading software and need to remove all animations and transitions from each one. I'd like to write a Powerpoint add-in that automatically does this when the file is loaded. I've figured out how to delete all animations using the following code in an auto_open() sub which I've imported as an add-in:
'Loop Through Each Slide in ActivePresentation
For Each sld In ActivePresentation.Slides
'Loop through each animation on slide
For x = sld.TimeLine.MainSequence.Count To 1 Step -1
'Remove Each Animation
sld.TimeLine.MainSequence.Item(x).Delete
Next x
Next sld
However, I'm not sure how to delete transitions with this method. I've essentially solved the problem visually by adding in this line,
sld.SlideShowTransition.Duration = 0
but I'd like to outright delete the transitions as they interfere with clients' screen-reading software. Deleting the object in the paradigmatic VBA way (SlideShowTransition.Delete) doesn't work.
Any ideas?
Thanks in advance.

This'll do it:
sld.SlideShowTransition.EntryEffect=0

Related

How can I select all in Powerpoint VBA?

I have been struggling for a while to find a VBA code to select all the slides and all the shapes of a presentation (for some reason this seems to be of no one's interest). I have tried to set up a range with all the slides and then select all the shapes of the range, but that does not work. I also try looping slide by slide and accumulate the selection (msoFalse), but for that you also need to activate each slide and I was unable to do that.
I think selecting all the slides and shapes at once is useful to manipulate the fonts or run a full spell check. Your help would be really appreciated!!
Selecting objects in VBA is generally to be avoided. It's unreliable and slow. Instead, loop through every shape on every slide and perform whatever operation you need:
Sub DoStuffToShapes()
Dim oSlide as Slide
Dim oShape as Shape
For each oSlide in ActivePresentation.Slides
For each oShape in oSlide.Shapes
'Do stuff to the shape
Next oShape
Next oSlide
End Sub
If you've created a font theme and applied it to the Slide Master and Layouts, it's usually easier and faster to change fonts by modifying the theme and/or master rather than using VBA. VBA isn't needed for a spellcheck either.

Is it possible to update only a selected linked object in PPT?

I'm trying to build a macro which will update only the selected linked object within a PowerPoint, but I cannot figure out how to do it.
The first part below is what I've used to update all linked objects, but I am currently dealing with massive Excel files, and presentations with 200+ linked objects, so one-at-a-time updating is the only way to go unfortunately.
The second part is what I was hoping would work.
First part:
Dim sld As Slide
Dim sh As Shape
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.Type = msoLinkedOLEObject Then
sh.LinkFormat.Update
End If
Next
Next
Second part:
With ActiveWindow.Selection
.LinkFormat.Update
EndWith
I'm pretty inexperienced with PPT VBA, so please bear with me. Is it possible to build something like this? (It's going to be part of a more complicated macro, so it ultimately will be more convenient than just Right Click + Update Link)
Give this a try:
Sub UpdateOLELink()
ActiveWindow.Selection.ShapeRange.LinkFormat.Update
End Sub

VBA Powerpoint : what is the VBA equivalent to "hyperlink to a different Powerpoint Presentation?

I want to use several slideshows (in kiosk mode if possible), to be able to jump between them, without going back in edit mode...
No problem to do it with shapes and "hyperlink to a different powerpoint presentation".
But i'd need to do it also in VBA macros, in some slides.
For example, after a quiz is finished, jump to another slideshowwindow and a given slide, and give focus to that slideshowwindow :
What would be the code like ?
I'm unable to give focus to the new slideshowwindow...
I suppose it is the equivalent of what "hyperlink to a different PPT Presentation does, but i can't figure to do it.
Thank you very much in advance !
Alex
This Code opens a Presentation goes to Slide Number 5 and starts in Kiosk Mode
Dim PowerPointApp As PowerPoint.Application
Dim myPPT As PowerPoint.Presentation
'Open the Slideshow
Set myPPT = PowerPointApp.Presentations.Open(FileName:="filename.pptx")
Application.ActivePresentation.SlideShowSettings.ShowType = ppShowTypeKiosk
'You need this to work
ActivePresentation.SlideShowWindow.View.Exit
ActivePresentation.SlideShowSettings.Run
'Goto Slide number 5
myPPT.Windows(1).View.GotoSlide 5
'Start Slide Show
myPPT.SlideShowSettings.Run

How do you run vba code when changing slides in powerpoint?

I'm trying to reset the contents of some text boxes and labels when I change slides, but I'm struggling to get it to work. I've come up with this after doing a lot of googling and searching, but it doesn't seem to work. I'm trying to use the OnSlideShowPageChange event in PowerPoint 2013 and 2016, but it seems to have no effect. I'm not used to working with PowerPoint vba, so I might be doing something completely wrong.
Edit: I've managed to find an alternative method of resetting the label text. I've managed to get it to reset when the user focuses on one of the text boxes or moves their mouse over the label. But, I'm still curious to know the answer to this question; I'm not sure why my code isn't working.
I'll be greatful if anyone can point out any issues and how to fix them.
Here's what I've got so far:
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
Dim Sld As Slide
If Wn.View.CurrentShowPosition = 9 Then
'Perform Updates for slide #9
Set Sld = Application.ActivePresentation.Slides(9)
Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
End If
If Wn.View.CurrentShowPosition = 18 Then
'Perform Updates for slide #18
Set Sld = Application.ActivePresentation.Slides(18)
Sld.Shapes(TextBox_Form_Name).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Email).TextFrame.TextRange.Text = ""
Sld.Shapes(TextBox_Form_Message).TextFrame.TextRange.Text = ""
Sld.Shapes(Label_Form_Info).TextFrame.TextRange.Text = ""
End If
End Sub
I've also tried putting the shape names in speech marks, but that doesn't seem to help.
By the way, I need the code to work in both PowerPoint 2013 and 2016.
Here's an answer from the PowerPoint FAQ at http://www.pptfaq.com
Suppose your code that depends on the OnSlideShowPageChange( SHW as SlideshowWindow ) event works when run from within VBA or when you launch the presentation from within PowerPoint, but not when you start the show by doubleclicking the icon for the PPS or PPSM. The slide show launches normally, but the code in your OnSlideShowPageChange subroutine never runs.
Solution
Add an Active-X control (from the Developer tab) on first slide (drag it just off the slide if you don't want it visible during the slide show).
This forces VBA to initialize when the presentation starts, so the event gets triggered and your code runs.

VBA code to auto update PowerPoint links to Word

I have hundreds of PowerPoint presentations that all have linked Word objects in them. How can I auto-update all of the links without opening each presentation? I'm assuming it'll be done with VBA, but the only VBA examples I can find are for auto-updating linked Excel objects. I'm not familiar enough with VBA to modify the code.
Ultimately, I'd like to run this via Command Prompt.
Using PowerPoint & Word 2013.
DragonSamu's right ... but to get you started, try this from within PPT itself, then work out how to rewrite it in a scripting language or something that will compile to an EXE
For each file you want to process, open the file (via code) then
Call UpdateLinks(ActivePresentation)
Sub UpdateLinks(oPres As Presentation)
Dim oSl As Slide
Dim oSh As Shape
For Each oSl In oPres.Slides
For Each oSh In oSl.Shapes
If oSh.Type = msoLinkedOLEObject Then
oSh.LinkFormat.Update
End If
Next
Next
End Sub