📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

How to create a Countdown Timer in PowerPoint across Multiple Slides using VBA Macros - Tutorial

Bhavesh Shaha - PowerPoint Games12:41

Transcription

In this video, I will be showing you how to make a countdown in PowerPoint. So, and a new Cline and change its layout to blank. Now choose a rectangle and draw it over here. Now, in shape format, select selection pane and change the name of this rectangle, which is currently rectangle clean, to countdown. Now we need to enable the Developer tab. To do that, go to File, click on Options, click on Customize Ribbon, and checkmark the Developer tab. Click OK. Now, go to the Developers tab, click on Macros, and add a macro called countdown. Click on Create.

Now we can do this the easy way or the hard way. The hard way, the easy way is to go to my website, scroll down, select the code, copy it, go to your Visual Basic panel, bestirred, close that, click on elect angle, go to Insert Actions, click on Run Macro, click OK, go to slideshow, and boom—we created a countdown for 30 seconds. They can change that very easily; just close this, go back to your View Code, stomp this for the time being. Now our countdown was 30 seconds, as given in this line of code: 30 seconds. Now, if I wanted it for, say, 5 minutes, I'll put 300 seconds. I close this and click on slideshow one more time, click on the blue box, and I have a countdown for 5 minutes. So you can just change that numerical here, and you can have a countdown for however many minutes you want. You can also design this client. So we created this very basic countdown timer in PowerPoint.

Now, what was the hard part? That is learning how the code works so you can customize it to the fullest. Now I will be covering these topics in the video: firstly, understanding the schematics of the code; second, adding a notification when the countdown is over; third, changing the time limit without touching the code; and after that, having this countdown throughout multiple slides. Say you have 10 questions slides having the same countdown; the same countdown will work throughout all those slides. So stay tuned, and if you haven't already, click on subscribe, click on like, and we will get started.

So, first, understanding the schematics of the cone on your screen now. You have two times: one is 10:30 p.m., and the next is 10:35 p.m., of the same name. So a spell Visual Basic coding: 10:35 p.m. is greater than the 10:30 p.m. value, and we can represent that mathematically by adding the greater than sign. Next is our Now function. This Now function gives us the exact Kullen time as per your system time. So right now, my system says it is 9:13. So if I just make a subroutine here called What's the time and a message box for Now and click on play, you will see that it shows 26 April 2029, 13:36 seconds. So that is what this Now function does, and we have stored this Now function in a variable called time, which is of the data type Date. So this will be represented as a date—simple enough.

So we now have two main parameters: one is the current time, which is here as Now, and a second is the current time, which is stored in the variable time. And in that, we add a countdown time, which is 300 seconds, and we are adding that by this function called Date. And so our variable time is actually a new future time, which is taken time plus 300 seconds. Let me explain that here. Now, if I copy this, we've stood in my new subroutine and add one more message box for time, you will be able to understand. So now let me play this subroutine, and the first message box shows the current time, which is 21:15. And now, if I click on OK, a new time should come—the new future time, which will be 5 minutes in the future, that will be 21:20. And as you can see, it shows 21:20 a second OK. So logically speaking, the current time is less than the new future time; 21:15 was less than 21:20. So until the current time itself passes or catches up to the new future time, we need to update the shape called countdown, which is Crescent in slide number 1, and we should update it with the difference of the new future time, which is 21:20, minus the current time, which is 21:15, and the subtraction should be shown in the format hh:mm:ss for hours, minutes, and seconds. As you can see here, this is the uh, this is a minute, this is the second. I will not be going deep into that. We are updating this, and we are updating this until the current time passes the set future time. So until that, this shape has to be updated with the difference of the future time minus the current time in the hours, minutes, seconds format, and we are putting this in the loop because the time changes every second, little e, and every second is a millisecond. Your box, your shape, has to be updated, and that is why we have this Do Until loop.

Now, in the second part, how do we show a notification when your time is over? So for that, they can add a simple If-Then routine. So if the current time is greater than the old set future time, so if a time comes which is greater than 21:20, you should have a message box saying Time up. So let me test this out now. So instead of 300 seconds, I've got five seconds. Let me go back to my presentation, click on slideshow, and click on this rectangle: the five, four, three, two, one, and Time up! And as you can see, it shows Time up. So now we had a message box showing Time up. What if we want to change the text inside the countdown? We can do that too. So if you want to change the text, use this code, and in the text of the shape countdown, we will be having Time up actor presentation, yep. So now let us test us again: three, two, one, zero, Time up! Time up! As you can see, the code works fantastically. Others, if you don't want to have any of these, you can also leave that at the user to maybe slide number two. So for that, we will be using the code ActivePresentation.SlideShowWindow.View.GoToSlide, and inside a bracket, type the slide number you want to be redirected to, so slide number two. Let me create slide number two, and in that, let me type Time up. So perfect. Let me go to slideshow mode again, click on this: three, two, one, and Time up! As you can see, I'm redirected to one more slide, and you open a loom of possibilities here, you, and you can put whatever code you want, you're not just Time up, not just the direction; you can choose any subroutine to occur in between this If condition. A practical example of that would be a question: once the time is up, I must be taken to the results line. And if you want to see how that works, you can click on the link in the description where I make a quiz game with a time limit.

Now, thirdly, instead of having a countdown for seconds, how can I have a countdown for minutes? In our DateAdd function, we have ss stands for seconds; 5s stands for five seconds. Now, if I wanted five minutes, instead of s, I put n; n stands for minutes, not mn. Now, if I go to slideshow mode one more time and click here, you see that there is a counter for five minutes. Escape, and I'll stop the code again. And if you do not listen or stop the code, we cannot add, I'll type anything, and that is annoying, is annoying. So just click on reset. But when your countdown is happening, you can definitely work on your PowerPoint, go to one more slide, open up questions, and do whatever you want because we all type in the code DoEvents. If you'll remove this, the whole PowerPoint will be frozen until the countdown is over. Now next, now how can you customize the format? If you do not want hh:mm:ss, maybe you want only the seconds, maybe you want only the minutes, how can you do that? That showing that we have this format hh:mm:ss. Now, if I wanted a countdown for 1 minute, I can just remove everything and seconds alone. Now close this, go to slideshow, click here, and I'll get a countdown for 1 minute, which is 60 seconds, and that works perfectly fine.

And now, at last, how can I have this countdown again in various slides? Let me just make the countdown smaller, place it in a corner, reduce the size. Now I can just have some navigation buttons: Previous slide and Next slide. So go to whom, find your shapes, and click on these action buttons. So this is for Next, and and we can choose one for the Previous, and we can place it over here. So you can duplicate the slides; the name of the shape should be countdown in all your slides. I have it in five slides, and in all these five slides, the name of the shape is countdown. So I can remove the Next button from my fifth slide and the Previous button from my first slide. So now, how can we have it in all these five slides? For that, we just need to make a For loop. So after this, create your For loop: For i = 1 To 5, which is 1, 2, 3, 4, 5, and they represent these five slides; Slides(ActivePresentation.Slides(i)). So i is replaced by 1, 2, 3, 4, and 5 respectively. Now I can close this, go to slide 1, and I can add the slide number here, so you'll be able to follow what is happening: slide 1. So now we have entered all the slide numbers. Now comes my favorite feature: take a text box, and in your slide one, outside is slide, type here: Enter your seconds. So now you can customize the time limit based on what number is entered inside this shape. So if I want to say 20 seconds, I will type 20, click on selection pane, and change the name of this rectangle to Time Limit. Great. So now we need to represent us in our code. So go to View Code, and in count, we have count = 1, but count should not equal 1; count should equal whatever is inside the shape called Time Limit. So, go to view code, and we need to type ActivePresentation.Slides(1).Shapes("Time Limit").TextFrame.TextRange. Perfect. And now this is 20 seconds, not 20 minutes, so change this n to s. Now we need to fix some other things too: when our countdown is over, only the first slide's countdown shows Time up, and other slides do not show that. So we can just add a For loop: For i = 1 To 5, and then Next i. Now, when the countdown is over, this should also go to slide number 6, not slide number 2. Now close this, and now we can test the module. Go to slideshow, click here. So we have 20, 19, 18; we can go to the next slide, we can go to the previous slide; it works great. For I fast-forwarded, and now three, two, one, and go to slide number six. Great. So that is how you make a countdown in PowerPoint. Remember, when you are saving this, always save in a macro-enabled presentation, max were nimble presentation, or macro-enabled show.

So this is a multiplication game which I coded and which was designed by my friend Aegis. So let me try to answer a few questions: 7 into 10, 70. Let me answer this incorrectly, and as you can see, the countdown works, and once the countdown is over, is over, using a notification, we will get a message box; it shows Correct, one wrong point. And this is how a countdown can be embedded in a practical situation in your PowerPoint games. So you can buy this template from my website if you are interested. That was a nice subtle promotion. So if you liked the video, hit the like button, subscribe, and if you have any doubts, leave a comment down below. Hopefully, this was useful. Thank you for watching; have a great day.