0% found this document useful (0 votes)
130 views2 pages

Macroscript For Interactive Powerpoint

This document contains VBA code for using text boxes, command buttons, combo boxes, and linking a quiz to an Excel spreadsheet in a Microsoft PowerPoint presentation. The code includes event handlers for clicking buttons and focusing on combo boxes to check text box entries and display feedback messages. It also includes a subroutine to save quiz results like the user's name, number of correct and incorrect answers, and percentage to an Excel file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views2 pages

Macroscript For Interactive Powerpoint

This document contains VBA code for using text boxes, command buttons, combo boxes, and linking a quiz to an Excel spreadsheet in a Microsoft PowerPoint presentation. The code includes event handlers for clicking buttons and focusing on combo boxes to check text box entries and display feedback messages. It also includes a subroutine to save quiz results like the user's name, number of correct and incorrect answers, and percentage to an Excel file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

USING THE TEXT BOX AND COMMANDBUTTON FOR FILL IN THE BLANK

Private Sub CommandButton1_Click()


If TextBox1.Text = "perfect form" Then
MsgBox "Correct! Nice Work"
Else: MsgBox "Opps! Try Again"
End If
End Sub

Private Sub CommandButton3_Click()


If TextBox3.Text = "organic farming" Then
MsgBox "WONDERFUL JOB. You got it right!"
Else
MsgBox "I think you missed the other details. TRY AGAIN."
End If
End Sub

USING THE COMBO BOX

Private Sub ComboBox1_GotFocus()


If ComboBox1.ListCount = 0 Then AddDropDownItems
End Sub

Sub AddDropDownItems()
ComboBox1.AddItem "1"
ComboBox1.AddItem "2"
ComboBox1.AddItem "3"
ComboBox1.AddItem "4"
ComboBox1.ListRows = 4
End Sub

INTERACTIVE QUIZ WITH MS EXCEL LINK

Dim numCorrect As Integer


Dim numIncorrect As Integer
Dim userName As String
Dim qAnswered As Boolean
Sub SaveToExcel() 'ADDED
Dim oXLApp As Object
Dim oWb As Object
Dim row As Long
Set oXLApp = CreateObject("Excel.Application")
'On a Mac change \ to : in the following line
Set oWb = oXLApp.Workbooks.Open(ActivePresentation.Path & "\" & "Results.xlsx")
If oWb.Worksheets(1).Range("A1") = "" Then
oWb.Worksheets(1).Range("A1") = "Name"
oWb.Worksheets(1).Range("B1") = "Number Correct"
oWb.Worksheets(1).Range("C1") = "Number Incorrect"
oWb.Worksheets(1).Range("D1") = "Percentage"
End If
row = 2
While oWb.Worksheets(1).Range("A" & row) <> ""
row = row + 1
Wend
oWb.Worksheets(1).Range("A" & row) = userName
oWb.Worksheets(1).Range("B" & row) = numCorrect
oWb.Worksheets(1).Range("C" & row) = numIncorrect
oWb.Worksheets(1).Range("D" & row) = 100 * (numCorrect / (numCorrect +
numIncorrect))
oWb.Save
oWb.Close
End Sub
Sub GetStarted()
Initialize
YourName
ActivePresentation.SlideShowWindow.View.Next
End Sub

Sub Initialize()
numCorrect = 0
numIncorrect = 0
qAnswered = False
End Sub

Sub YourName()
userName = InputBox("Type your name")
End Sub

Sub RightAnswer()
If qAnswered = False Then
numCorrect = numCorrect + 1
End If
qAnswered = False
MsgBox "You are doing well, " & userName
ActivePresentation.SlideShowWindow.View.Next
End Sub

Sub WrongAnswer()
If qAnswered = False Then
numIncorrect = numIncorrect + 1
End If
qAnswered = True
MsgBox "Try to do better next time, " & userName
End Sub
Sub Feedback()
MsgBox "You got " & numCorrect & " out of " _
& numCorrect + numIncorrect & ", " & userName
SaveToExcel 'ADDED
End Sub

You might also like