One of the assignments I set each year is for a group of students to prepare a narrated powerpoint presentation. It’s a useful exercise (I think), the students get to practise some of the presentation skills we try to teach and they can get to put a talk together in a way that appropriate for online/computer use.
However, in the marking scheme is a timing criteria. The presentation has to be between 15-20 minutes long. Most go over that time, and there a small marking penalty for that, but obtaining an accurate figure of how long the whole presentation is is tricky. I usually listen to the whole presentation with a stopwatch and try not to loose too much time during the slide transitions.
I wanted to see if I could get some vba code to count the length of the sound clips and combine them together to give me a total ‘sound length’. It took me some digging, but this is what I came up with.
Sub SoundLength() 'declare the variables Dim sld As Slide Dim so As Shape Dim SL As Long Dim Totalmin As Integer Dim Totalsec As Integer 'reset the key variable SL = 0 total = 0 For Each sld In ActivePresentation.Slides 'loops through ecah slide in the file For Each so In sld.Shapes 'loops through each shape in the slide If so.Type = msoMedia Then 'if the shape is a sound clip then... If so.MediaType = ppMediaTypeSound Then total = total + so.MediaFormat.Length 'count the length of the sound in milliseconds ' and adds it to a running total End If End If Next Next sld total = total / 60000 'returns the total number of seconds Totalmin = Int(total) 'calculate the number of minutes Totalsec = Int((total - Totalmin) * 60) 'calculate the remain no. of seconds MsgBox (Totalmin & "min/" & Totalsec & "sec") End Sub
How do you get it to work?
Open powerpoint. Press Alt + F11 and this should open the Developer/VBA window. Go to the menu bar and click insert, and insert a module. Copy the above code into the code window. It should look like the banner image for this block post. Save the powerpoint file as some suitable name. Open the powerpoint file you want to analyse, and then click on the window containing the code and then run the macro (the wee green triangle, or the Run in the menu bar). A window will pop up with the minutes and seconds.
References and comments
- This link really got me going
- I had lots of help from docs.microsoft.com