Showing posts with label Powerpoint VBA. Show all posts

POWERPOINT VBA for Quiz Management (With Pictures)


Several years after the release of Microsoft PowerPoint, many users were yet to discover the true Power of the MS PowerPoint in terms of quiz management and programming.
In this tutorial, I will show you some of these features and we shall look into some VBA Programming features.
OH! You are new to programming? Don’t worry I had arranged everything in such a way you will understand.
If you are new to VBA, then read VBA Programming

Let’s swing into action:
1.   Open your Microsoft PowerPoint 2007 (recommended)
In the first slide’s title text box, we are going to type something like ‘WORLD QUIZ’ in there, so get your seat and type… 
2.  Create two (2) additional slides
      To create new slides, on the Home Tab, click on New Slide to create new slides. Don’t forget that we need 2 slides, which mean you will click it twice. You got that? Yes, I meant the slides? Good!
 




3.   Input the following on each of the title text box of the new created slides;
On second slide…..Input - How many days are in a year?
On the third slide…..Input – The first letter of the English alphabet is?

4.   To avoid confusion, we are going to delete all the subtitles text boxes of all the slides. Left click on them, then press ‘Delete’ on your keyboard.

5.   We are going to use the action buttons to input the multiple answers.
      An action button is a button which does an action when clicked. Think of pressing the power button of your mobile phone, the phone respond to your press by turning on. This is in likeliness with the action buttons. When pressed, they does a specific action. More on that later!
On the first slide, insert an action button. If you are confuse, you can check the image(s) for clarity, ok?

To insert an action button,
Go to insert choose shapes, under the action button category, choose custom.
Then hold and drag to draw the button, release the button. Oh! That pop-up window is not useful now, close it! Now, draw another on the second slide. Yes, like that! Very good!













 


6.   Duplicate the box on the second slide into 3, with the original, that make them four (this is the number of choice your multiple choices quiz will have)
To duplicate,
Click and hold the left mouse button, press and hold Ctrl + Shift too.














Move it some space from the original one and release the mouse click. Make sure to hold the Ctrl and Shift key together. I hope you got that? Good!
7.   Duplicate the four action buttons on slide 2 to slide 3.
To do that, hold down shift key, now click on each of the four action boxes to select them. Right click on one of them, choose copy or press Ctrl + C. Now, go to the third slide and press Ctrl + V to paste it.
8.   Time to input the answers!
Go to slide 2, right-click on the first action button and select ‘Edit Text’.
Write ‘300’,
Do the same for each of the three remaining buttons
On the second action button, write ‘250’; third write ‘365’; fourth write ‘366’
* To add text to other buttons, right-click on them & select ‘Edit Text’.
Go to slide 3, perform the same action as above,
On the first action button write ‘A’; On the second action button write ‘B’; On the third action button write ‘C’; On the first action button write ‘D
Don’t forget that the main function of the action buttons is to perform an action when they were clicked. To make it more interactive, we will write a code which will tell the user if the answer he/she chose is right or wrong. That’s where VBA comes in.














Are you new to VBA? You can read VBA Programming
After following the link above you can then come back. “It is always a good measure to know what you need to know”.
9.  On the PowerPoint menu bar, select the ‘Developer’ tab.
      In case, it is not there, follow these steps:
a.       click on the MS Office button
b.      Select ‘PowerPoint Options
c.       On the ‘PowerPoint Options Screen’, check the ‘Show Developer Tab in the Ribbon
d.      Click ‘OK’
Under the developer tab, select ‘Visual Basic’. I hope you got that? Good! For the purpose of this tutorial, we will consider module as the tag of our code.
On the new window of Visual Basic, select the insert tab, choose ‘Module
Write this:
Sub Username()
Dim Username As String
Username = Inputbox (prompt:=”Enter your name”, title:=”Enter your details”)
Activepresentation.slideshowindow.view.next
End Sub

Sub RightAns()
Msgbox(“Good Job!”)
Activepresentation.slideshowindow.view.next
End Sub

Sub WrongAns()
Msgbox(“Please Try Again”)
Activepresentation.slideshowindow.view.next
End Sub
















Close the VBA window
If you don’t understand the code above, read the post on VBA Programming

10.      For easy access and for our code to run without obstruction, we need to save the presentation as a ‘macro-enabled’.
Choose ‘Save As’ from the office button. Set the ‘Save as type’ to ‘PowerPoint Macro-Enabled Presentation
















 11. What is left for us to do, is to link our code to the action buttons.
      Go to Slide 1, right-click on the ‘Proceed’ button, choose ‘Edit hyperlink’, then proceed and choose ‘Hyperlink to’, click on Run macro to enable the box, now choose ‘Username’….Click OK.




















For slide 2 & 3, same procedure as above, all you have to do is just link the run macro to ‘WrongAns’ for wrong answers and link ‘RightAns’ for right answers.





















To preview your work, go to View Slide show. Or you can press F5 on your keyboard.

VBA PROGRAMMING

Programming on its own is an important aspect of computing, it enables us to turn the computer into a command-obeying machine. Through programming, we can control the computer to our taste; we can tell it what to do; when to do it; how to do it; in fact, we can tell the computer how to think! Surprised? Well you will soon find out how fun it is to become a programmer or a scripter.
For the purpose of this tutorial, we shall look into the in-built programming language of many applications, Virtual Basic for Application (VBA) by name. 
Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven programming language Visual Basic 6 and its associated integrated development environment (IDE).


VBA came into existence when the need for scripting is at climax. It is a general application language that commonly used applications like Microsoft Office and CorelDraw Graphic Suites make use of nowadays. With VBA, you can change the fonts, designs, or formats of your data. It is widely use in MS Word, PowerPoint, Publisher and Excel.

You can also read: Powerpoint VBA for Quiz Management
 
Code 1 (Our First Program)
VBA like other programming languages have two significant words that mark the beginning and the ending of its programs.
Below is a traditional ‘Hello World’ program in VBA.
Sub Helloworld()
Msgbox (“Helloworld!”)
End Sub.

Explanation
Sub Helloworld()  { Sub tells the computer that we want it to name our new program “Helloworld”
The “msgbox” made the computer to understand that we need a message box to display our message
Helloworld!” tells the computer to print what was in the colon on the message box screen (in this case ‘Helloworld’)
Then “End Sub” ends the program.
You can try changing the Helloworld into anything you wish and see the show flow!
·         You can load VBA via MS Word, PowerPoint or Excel. Open it via the Developer tab on the menu bar.

The InputBox
On many occasions, we may want the computer to collect some pieces of information (data like name, age or sex), in such case, we want the computer to provide a box with which we can input our particulars. That’s were inputbox come in.
Think of your computer as a big house containing several rooms with each room having different boxes. Let’s assume in one of the boxes, you want to keep names, in another you want to keep age. This means that the major aim of the inputbox is to keep records. You got that? Good! You’re great!
On this note, we are going to introduce an important aspect of VBA programming
Variables
Now, remember the previous illustration of a house with rooms of different boxes. Now, we want to store names but we need to tell the computer to name the box something like “Username”. That is where variables comes in, it comprises of anything ranging from numbers to letters or characters. Note that there are some words we can’t use because they were RESERVED WORDS.
Oh! We want the computer to save some data but in the computer’s memory (the illustration earlier), there were many rooms, some for letters, others for characters or numbers. This mean we will have to tell the computer the type of data we have planned to save. Will it be letters or numbers? That introduces us to the ‘dim’ function of the VBA.
‘dim’ is used as preface to tell the computer what type of data that will be stored.
Data types may be String, Integer, long, short, to name but few.

Code 2
We are going to write codes that prompt the user to input something, which will then be stored in the computer memory for later use.
Sub Username ()
Dim Username As String
Username = inputbox (prompt:=”Enter your name”, title:=”Name”)
End sub.
The second line above tells the computer to label a box ‘Username’; the box will contain string types of data.
The third line tells the computer to store anything typed in the input box into our previous ‘Username’ box.

I hope you had found this article useful. More updates soon. Drop your comments below.