PDA

View Full Version : Animation by Paragraph



El_Ingeniero
09-23-2023, 04:13 AM
Dear all,

I've been racking my brains for a while now and I have no idea why this simple code doesn't work. Powerpoint Plus 2019.

I want VBA to apply Fade in to a bullet list in a textbox or placeholder, each line appearing by Paragraph on click anywhere on slide. Code seems fine, but the last line triggers an error: "Compile error: Method or Data member not found".

Any help appreciated!! Thanks in advance


Sub ApplyTextAnimation()
Dim slide As slide
Dim shape As shape
Dim effect As effect
Set slide = ActivePresentation.Slides(1)
Set shape = slide.Shapes(1)
Set effect = slide.TimeLine.MainSequence.AddEffect(shape:=shape, effectId:=msoAnimEffectFade, trigger:=msoAnimTriggerOnPageClick)
effect.TextUnitEffect = msoAnimTextUnitByParagraph
End Sub

Aussiebear
09-23-2023, 04:28 AM
Welcome to VBAX El_Ingeniero. Someone will be along soon hopefully to answer your query. BTW when supplying code to this forum, please wrap your code with code tags. See the first line in my signature as to how it needs to be done. Thank you.

John Wilson
09-23-2023, 04:57 AM
Dear all,

I've been racking my brains for a while now and I have no idea why this simple code doesn't work. Powerpoint Plus 2019.

I want VBA to apply Fade in to a bullet list in a textbox or placeholder, each line appearing by Paragraph on click anywhere on slide. Code seems fine, but the last line triggers an error: "Compile error: Method or Data member not found".

Any help appreciated!! Thanks in advance


Sub ApplyTextAnimation()
Dim slide As slide
Dim shape As shape
Dim effect As effect
Set slide = ActivePresentation.Slides(1)
Set shape = slide.Shapes(1)
Set effect = slide.TimeLine.MainSequence.AddEffect(shape:=shape, effectId:=msoAnimEffectFade, trigger:=msoAnimTriggerOnPageClick)
effect.TextUnitEffect = msoAnimTextUnitByParagraph
End Sub


Sub ApplyTextAnimation()
Dim osld As slide
Dim oshp As shape
Dim oeff As effect
Set osld = ActivePresentation.Slides(1)
Set oshp = osld.Shapes(2)
Set oeff = osld.TimeLine.MainSequence.AddEffect(shape:=oshp, effectId:=msoAnimEffectFade, Level:=msoAnimateTextByFirstLevel, trigger:=msoAnimTriggerOnPageClick)
End Sub

However you mentioned Shapes(1) - if you are trying to animate a Title Placeholder by paragraph it will always fail even if you use the GUI because titles only have one (real) paragraph.

John Wilson
09-23-2023, 05:49 AM
Sub ApplyTextAnimation()
Dim osld As slide
Dim oshp As shape
Dim oeff As effect
Set osld = ActivePresentation.Slides(1)
Set oshp = osld.Shapes(2)
Set oeff = osld.TimeLine.MainSequence.AddEffect(shape:=oshp, effectId:=msoAnimEffectFade, Level:=msoAnimateTextByFirstLevel, trigger:=msoAnimTriggerOnPageClick)
End Sub

However you mentioned Shapes(1) - if you are trying to animate a Title Placeholder by paragraph it will always fail even if you use the GUI because titles only have one (real) paragraph.

PS TextUnitEffect is legacy code from pre 2007 versions + it's not a good idea to use Shape /Slide etc for object variables of the same type - it will soon lead to confusion.

El_Ingeniero
09-24-2023, 04:36 AM
Thanks for the prompt reply & welcome - sorry, I will use tags next time!

El_Ingeniero
09-24-2023, 04:43 AM
PS TextUnitEffect is legacy code from pre 2007 versions + it's not a good idea to use Shape /Slide etc for object variables of the same type - it will soon lead to confusion.

Thanks for your comments John!

Argh! So there is no way of achieving what I'm trying to do? It's so basic I would have thought I'd be a piece of cake. Shame PPT doesn't have a macro record tool, what usually do is (after selecting text placeholder)

Apply Fade In
Effect Options > Appear by paragraph

I've tried asking Chat GPT, but its code is worse than mine!

John Wilson
09-28-2023, 10:03 AM
Of course there's a way to do this . Did you look at the code I posted?