Solved

VBA to Automatically Start Animation

Posted on 2014-12-19
7
737 Views
Last Modified: 2014-12-19
0
Comment
Question by:Eirman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 12

Accepted Solution

by:
Jamie Garroch earned 500 total points
ID: 40509104
Try this Eirman:

' ===================================================================================
' PowerPoint VBA Macro
' Author : Jamie Garroch
' Date : 19DEC2014
' Copyright (c) 2014 GMARK Ltd. http://youpresent.biz
' Source code is provide under Creative Commons Attribution License
' This means you must give credit for our original creation in the following form:
' "Includes code created by GMARK Ltd. (YOUpresent.biz)"
' Commons Deed @ http://creativecommons.org/licenses/by/3.0/
' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode
' ===================================================================================
' Purpose : make the shape-implemented timer trigger automatically
' Dependencies : A shape-stack Countdown Timer from A6 Training & Consultancy Ltd.
'                http://www.a6training.co.uk/resources_powerpoint.php
'                http://www.a6training.co.uk/resources/ImprovedPowerPointTimers.pptx
' Usage : 1. Select and copy all the shapes in a timer shape stack
'         2. Paste the shape stack to a slide without any other animation*
'         3. With the shape stack selected on the target slide, press
'            Alt-F8 and run the MakeTimerAutomatic macro
'
' Tested with the 60 second stack on slide 4 only
' * The code could be modified to check the relevant sequence as required
'
' How it works:
'   - The user copies and pastes the shape stack to a target slide
'   - The macro looks at each animation effect in the interactive (trigger) sequence
'   - Each effect is copied and recreated in the main timeline sequence
'   - All effects in the interactive sequence are deleted
' ===================================================================================

Option Explicit

Sub MakeTimerAutomatic()

  ' Do some basic selection checks
  If Not ActiveWindow.Selection.Type = ppSelectionShapes Then GoTo selectionError
  If Not ActiveWindow.Selection.ShapeRange.Count > 0 Then GoTo selectionError

  Dim oShp As Shape
  Dim oSld As Slide
  Dim effectShape As Shape, effectType As MsoAnimEffect, effectDuration As Single, effectDelay As Single, effectExit As Boolean
  Dim effectID As Integer
  Dim oEffect As Effect
  Dim iEffects As Integer
  
  ' Get a reference to the slide on which the selection was made
  Set oSld = ActiveWindow.Selection.ShapeRange.Parent
  
  ' Loop through each animation effect in the interactive trigger sequence, copying its parameters before recreating the effect in the main sequence
  With oSld.TimeLine.InteractiveSequences(1)
    iEffects = oSld.TimeLine.InteractiveSequences(1).Count
    For effectID = 1 To .Count
      ' Copy the relevant animation effect properties from the interactive trigger sequence
      effectType = .Item(effectID).effectType
      effectDuration = .Item(effectID).Timing.Duration
      effectDelay = .Item(effectID).Timing.TriggerDelayTime
      effectExit = .Item(effectID).Exit
      Set effectShape = .Item(effectID).Shape
      ' Add a new effect to the main (non-interactive) sequence
      Set oEffect = oSld.TimeLine.MainSequence.AddEffect(effectShape, effectType, , msoAnimTriggerAfterPrevious)
      oEffect.Exit = effectExit
      oEffect.Timing.TriggerDelayTime = effectDelay
    Next
  End With
  
  ' Delete the effects from the interactive trigger sequence (need to count backwards in the collection)
  For effectID = oSld.TimeLine.InteractiveSequences(1).Count To 1 Step -1
    oSld.TimeLine.InteractiveSequences(1).Item(effectID).Delete
  Next
  
  ' Provide the user with feedback
  MsgBox iEffects & " animation effects have been converted from the interactive trigger sequence to the main timeline sequence.", _
    vbInformation + vbOKOnly, "Macro by youpresent.biz"
Exit Sub

selectionError:
  MsgBox "Please select a group of shapes representing a timer.", vbCritical + vbOKOnly, "Selection Error"
End Sub

Open in new window

0
 
LVL 24

Author Comment

by:Eirman
ID: 40509185
I'm used to VBA in Access.  I can pop code into the OnLoad event of a form or whatever.
In PowerPoint I can only seem create a module which is stand-alone. (I've only been using PP for a few hours)

Where do I put the code Jamie?
0
 
LVL 12

Expert Comment

by:Jamie Garroch
ID: 40509299
Ah - sorry Eirman. Assumption is a bad habit!

Check out our article if you've never used VBA before:

http://youpresent.biz/copy-vba-macro-powerpoint-windows-mac/
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Author Comment

by:Eirman
ID: 40509302
I'm working with a new clean file.
I tried the Alt+F8 and it worked ...... once. When I save .... close .... open it doesn't work.

Perhaps something simpler, after all, it only needs a single click to get things started.
0
 
LVL 12

Expert Comment

by:Jamie Garroch
ID: 40509323
That's expected behaviour.

When you insert VBA code into a Microsoft Office file it must be saved using one of the macro-enabled formats. For example, in PowerPoint you could use .pptm. If you try to use the default .pptx extension then the VBA project is removed before the file is saved. You could develop your presentation in "macro mode" and then save it as a .pptx when you've finished.

So the VBA code works :-)
0
 
LVL 24

Author Comment

by:Eirman
ID: 40509326
I've requested that this question be closed as follows:

Accepted answer: 0 points for Eirman's comment #a40509185

for the following reason:

Got it .... thanks .... nice coding and commentary.
0
 
LVL 24

Author Closing Comment

by:Eirman
ID: 40509327
Got it .... thanks .... nice coding and commentary.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to make a simple, pseudo-random number generator in Microsoft PowerPoint. The code checks the generated numbers against a list of numbers already generated to prevent duplication. We used this as a youth group activity but…
 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question