PDA

View Full Version : Moving typewriter text box up screen



Chris1969
08-13-2022, 12:26 PM
Hello

I'm trying to use Powerpoint VBA to get a text box to move smoothly up a screen. The box has an entry animation with the text set to appear by letter (to create a typewriter effect). I then want to click on a command buttom to make the box move smoothly up the screen. The code which does this is below : the text box is called 'TxtPrint'.
The problem is that when I click the button the text box just disappears. I have tried the same code with other types of shape and it works as intended, so there is a problem with how I am applying it to text boxes.


I am aware that it is straightforward to do this using animations in 'core' powerpoint. However I want to understand the basics of doing it in VBA so I can apply it to more complex problems. Grateful for any advice which people can offer.

Thanks

Chris


Private Sub Button_Click()
Dim objSequence As Sequence
Dim objTxt1 As Shape
Dim objEffect1 As Effect
Dim sld As Slide
Set sld = ActivePresentation.Slides(3)
Set objTxt1 = sld.Shapes("TxtPrint")
Set objSequence = sld.TimeLine.MainSequence
Set objEffect1 = objSequence.AddEffect(Shape:=objTxt1, EffectID:=msoAnimEffectFloat, trigger:=msoAnimTriggerOnClick)
objEffect1.EffectType = msoAnimEffectPathUp
'objEffect1.Exit = msoTrue
End Sub

John Wilson
08-14-2022, 05:10 AM
First the code is fine except that it should be trigger:=msoAnimTriggerOnPageClick
Second usually best to use a standard shape to trigger vba and the use Insert > Action > Run Macro. You do not need to use command buttons

Last the main problem.

When you run vba in show mode on a slide that also has animation - usually the slide will be reset to the start (ie BEFORE the animation that shows the text box. This is probably why it disappears. The answer is sadly do not mix animation and vba. But it is possible to go to a specific lick in the animations which MIGHT work for you = change the number of course


SlideShowWindows(1).View.GotoClick (1)