How to get results reported to email from macro action PPT - vba

I have a PPT quiz that functions of macro actions. It counts the numberCorrect and the numberWrong and reports these scores to the user at the end of the quiz when they press the "see my results" box.
I would like these scores to be automatically reported to me when they select this box because I do not want the users taking the test numerous times prior to submitting their results.
Everyone will be using a G-mail account.
Here is my current visual basic module if that helps:
Dim UserName As String
Dim numberCorrect As Integer
Dim numberWrong As Integer
Sub YourName()
UserName = InputBox(Prompt:="Type Your Name!")
MsgBox " Good Luck " + UserName, vbApplicationModal, " IEE Recognition Training"
End Sub
Sub Correct()
MsgBox " Well Done! That's The Correct Answer " + UserName, vbApplicationModal, " IEE Recognition Training"
numberCorrect = numberCorrect + 1
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Wrong()
MsgBox " Sorry! That's The Wrong Answer " + UserName, vbApplicationModal, " IEE Recognition Training"
numberWrong = numberWrong + 1
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Start()
numberCorrect = 0
numberWrong = 0
YourName
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Results()
MsgBox ("You Got " & numberCorrect & " Correct Answers, " & numberWrong & " Wrong Answers, " & UserName), vbApplicationModal, " IEE Recognition Training"
End Sub
Any help is greatly appreciated !!! Thanks!

You could do this easily with the Outlook object model in VBA but are the users using that client to connect to GMail accounts or are they using a web client? If you don't use an Outlook object in your VBA code, you'd be looking at direct use of SMTP which is a much more complicated beast. Here is an Outlook snippet using late binding:
Set oOL = CreateObject("Outlook.Application")
Set oEmail = oOL.CreateItem(0) ' olMailItem = 0
With oEmail
.BodyFormat = 1 ' olFormatPlain = 1
.Subject = "Automatic results"
.Body = "You Got " & numberCorrect & " Correct Answers, " & numberWrong & " Wrong Answers, " & UserName
.To = "admin#mydomain.com"
.Send
End With
Set oOL = Nothing: Set oEmail = Nothing

Related

Email recipient name verification [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
This post was edited and submitted for review 10 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
There is a tool in outlook that notifies a sender about possible missing attachments as they click the send button. This tool seems to search the body of the email for keywords like "attachment" and then check to see if anything is attached to the email. If not, the notification then pops up.
I'm looking for something similar but a bit more advanced. I would like a similar notification pop-up to appear when the body of my email does not contain neither the first name nor the last name of my recipient(s).
EDIT / UPDATE
I have eventually created my own VBA code to solve this problem, based on FaneDuru's answer. Please consider unclosing this question.
Note: my code searches for either the first, middle(s) or last name of each one of the recipients, but only on the first two lines of the body of the email.
If any one of these searches is successful (i.e. if the name is found on the first 2 lines), then the check is successful and the email can be sent, otherwise the sender is notified.
When the recipient's email address is not in the address book of the sender, the programme does other similar things that can be easily seen in the code.
Please feel free to suggest improvements.
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) = "MailItem" Then
Dim myMail As MailItem, recip As Recipient, strNoRef As String, msg As VbMsgBoxResult, msge As VbMsgBoxResult, noEntry As String
Dim i As Integer
Dim j As Integer
Dim Lines() As String
Dim fLines As String
i = 0
j = 0
Set myMail = Item
Lines = Split(myMail.Body, vbCrLf, 4)
fLines = Lines(0) & Lines(1) & Lines(2)
For Each recip In myMail.Recipients
If recip.Address <> recip.AddressEntry Then
i = i + 1
If Not NameExists(recip.AddressEntry, fLines) Then
j = j + 1
strNoRef = strNoRef & recip.AddressEntry & vbCrLf
End If
End If
Next
For Each recip In myMail.Recipients
If Not recip.Address <> recip.AddressEntry Then
noEntry = noEntry & recip.AddressEntry & vbCrLf
End If
Next
If j = i And noEntry = "" Then
msg = MsgBox("This mail does not contain a reference to anyone of the following:" & vbCrLf & _
vbCrLf & strNoRef & vbCrLf & _
"To send the mail anyway, please press ""Yes"".", vbYesNo, "Send the mail?")
If msg <> vbYes Then Cancel = True
End If
If j = i And noEntry <> "" Then
msg = MsgBox("This mail does not contain a reference to anyone of the following:" & vbCrLf & _
vbCrLf & strNoRef & vbCrLf & _
"And the following recipients are not in the address book:" & vbCrLf & _
vbCrLf & noEntry & vbCrLf & _
"To send the mail anyway, please press ""Yes"".", vbYesNo, "Send the mail?")
If msg <> vbYes Then Cancel = True
End If
If noEntry <> "" And j < i Then
msge = MsgBox("The following recipients are not in the address book:" & vbCrLf & _
vbCrLf & noEntry & vbCrLf & "So, the email was not sent." & vbCrLf & _
"To send it, please press ""Yes"".", vbYesNo, "Send the mail?")
If msge <> vbYes Then Cancel = True
End If
If noEntry = "" And j < i Then
Cancel = False
End If
End If
End Sub
Function NameExists(strName As String, strBody As String) As Boolean
Dim arrName, El
arrName = Split(strName, " ")
For Each El In arrName
If InStr(1, strBody, El, vbBinaryCompare) > 0 Then
NameExists = True: Exit Function
End If
Next El
End Function
In order to achieve what you try explaining, please proceed in the next way:
Change Outlook security settings to make it open with Macro Enabled:
File - Options - Trust Center - Trust Center Settings... - Macro Settings and choose Notifications for all Macros, or Enable All Macros (not recommended.... Press 'OK', of course...
Close and reopen Outlook, choosing Enable Macros!
Press F11 in order to access VBE (Visual Basic for Applications) window. In its left pane you will see Project1 (VBAProject.OTM).
Expand Microsoft Outlook Objects and double click on ThisOutlookSession.
In the opening window (to the right side), please copy the next code:
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) = "MailItem" Then
Dim myMail As MailItem, recip As Recipient, strNoRef As String, msg As VbMsgBoxResult, noEntry As String
Set myMail = Item 'just to benefit of intellisense suggestions...
For Each recip In myMail.Recipients 'iterate between mail recipients
If recip.Address <> recip.AddressEntry Then 'if the address has a name (not only xxx#domain.com):
If Not NameExists(recip.AddressEntry, myMail.Body) Then 'check if one of its names (first or last) exists
strNoRef = strNoRef & recip.AddressEntry & vbCrLf 'if not, build a string to be used in the message
End If
Else
noEntry = noEntry & recip.AddressEntry & vbCrLf
End If
Next
If noEntry <> "" Then
MsgBox "The following recipients are not in the address book:" & vbCrLf & _
vbCrLf & noEntry
End If
If strNoRef <> "" Then
msg = MsgBox("The mail you try sending does not contain a reference to" & vbCrLf & _
vbCrLf & strNoRef & vbCrLf & "and it cannot be sent..." & vbCrLf & _
"To send it as it is, please press ""Yes"".", vbYesNo, "Send the mail?")
If msg <> vbYes Then Cancel = True 'if not pressing "Yes", the sending will be cancelled
End If
End If
End Sub
Function NameExists(strName As String, strBody As String) As Boolean
Dim arrName, El
arrName = Split(strName, " ")
For Each El In arrName
If InStr(1, strBody, El, vbBinaryCompare) > 0 Then
NameExists = True: Exit Function
End If
Next El
End Function
It would be good to press Save on the VBE Standard toolbar. I thing Ctrl + S will also work...
Try playing with mails and send some feedback...

How to send follow up email if no response?

In the code below I don’t understand how the subroutine checks if the emails coming through are a reply of an email previously sent.
The first subroutine seems to check if the subject line of an incoming email matches this condition: "re: " & strSubject Or InStr(LCase(Item.Subject), strSubject)
After that I am confused. The only way the code works for me is by using categories. It does not work as shown below.
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInboxItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
'If receive the reply, clear the flag and remove the reminder
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim objSentItems As Outlook.Items
Dim objVariant As Variant
Dim i As Long
Dim strSubject As String
Dim dSendTime As String
Set objSentItems = Outlook.Application.Session.GetDefaultFolder(olFolderSentMail).Items
If Item.Class = olMail Then
For i = 1 To objSentItems.Count
If objSentItems.Item(i).Class = olMail And **objSentItems.Item(i).categories = "Not Completed"** Then
Set objVariant = objSentItems.Item(i)
strSubject = LCase(objVariant.Subject)
dSendTime = objVariant.SentOn
If LCase(Item.Subject) = "re: " & strSubject Or InStr(LCase(Item.Subject), strSubject) > 0 Then
If Item.SentOn > dSendTime Then
With objVariant
.ClearTaskFlag
.ReminderSet = False
.Save
End With
End If
End If
End If
Next i
End If
End Sub
'Get a prompt asking if to send a notification email
Private Sub Application_Reminder(ByVal Item As Object)
Dim strPrompt As String
Dim nResponse As Integer
Dim objFollowUpMail As Outlook.MailItem
'You can change the subject as per your real case
If (Item.Class = olMail) And (LCase(Item.Subject) = "datanumen outlook repair") Then
strPrompt = "You haven't yet recieved the reply of " & Chr(34) & Item.Subject & Chr(34) & " within your expected time. Do you want to send a follow-up notification email?"
nResponse = MsgBox(strPrompt, vbYesNo + vbQuestion, "Confirm to Send a Follow-Up Notification Email")
If nResponse = vbYes Then
Set objFollowUpMail = Application.CreateItem(olMailItem)
With objFollowUpMail
.To = Item.Recipients.Item(1).Address
.Subject = "Follow Up: " & Chr(34) & Item.Subject & Chr(34)
.Body = "Please respond to my email " & Chr(34) & Item.Subject & Chr(34) & "as soon as possible"
.attachments.Add Item
.Display
End With
End If
End If
End Sub
The code just needs better commenting. The basic logic is: When a new email comes in, check if it's a reply to any email in the sent box. If so, remove the task and reminder flags from the sent email.
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInboxItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
'If receive the reply, clear the flag and remove the reminder
Private Sub objInboxItems_ItemAdd(ByVal Item As Object) 'New item received in inbox
Dim objSentItems As Outlook.Items
Dim objVariant As Variant
Dim i As Long
Dim strSubject As String
Dim dSendTime As String
' get all emails in sent box
Set objSentItems = Outlook.Application.Session.GetDefaultFolder(olFolderSentMail).Items
If Item.Class = olMail Then 'if new inbox item is email
For i = 1 To objSentItems.Count 'for each item in sent box
If objSentItems.Item(i).Class = olMail Then ' if sent item is email
Set objVariant = objSentItems.Item(i) 'sent email
strSubject = LCase(objVariant.Subject) 'sent email subject
dSendTime = objVariant.SentOn 'sent email send date
'Check subject, if new email is reply to sent email, or new email subject contains sent email subject
If LCase(Item.Subject) = "re: " & strSubject Or InStr(LCase(Item.Subject), strSubject) > 0 Then
If Item.SentOn > dSendTime Then ' if new email has later send date then sent email (else can't be reply)
With objVariant 'with sent email
.ClearTaskFlag ' clear flag
.ReminderSet = False 'remove reminder
.Save
End With
End If
End If
End If
Next i
End If
End Sub
The code listed above is badly written and wrong in general. The ItemAdd event is fired when an item is added to the folder, not received. For example, a user may move some items from one folder to another triggering this event. If you want to handle all incoming emails you need to handle the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
For i = 1 To objSentItems.Count 'for each item in sent box
If objSentItems.Item(i).Class = olMail Then ' if sent item is email
Instead of interating over all items in the folder and finding items that correspond to your conditions I'd recommend using the Find/FindNext or Restrict methods of the Items class. Read more about these methods in the following articles:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
I tried to recreate the situation, given flags are not reliable in my setup.
It may be possible to remove reminders by reinitializing ReminderTime.
Code for ThisOutlookSession
Option Explicit
Public WithEvents objInboxItems As Items
Private Sub Application_Startup()
Set objInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub test_objInboxItems_ItemAdd()
' For testing select a reply to the flagged sent item
objInboxItems_ItemAdd ActiveExplorer.Selection(1)
End Sub
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
' If reply received,
' clear the flag and remove the reminder from the corresponding sent item
' No attempt to make the logic efficient
' - Find / Restrict in the sent items folder
' In my setup
' - TaskDueDate is always 4501-01-01 (no date)
' - Reminders on mailitems are not functional
Dim objSentItems As Items
Dim objVariant As Variant
Dim i As Long
Dim strSubject As String
Set objSentItems = Session.GetDefaultFolder(olFolderSentMail).Items
If Item.Class = olmail Then
Debug.Print
Debug.Print "Item.Subject ...........: " & Item.Subject
For i = 1 To objSentItems.Count
If objSentItems.Item(i).Class = olmail Then
Set objVariant = objSentItems.Item(i)
strSubject = LCase(objVariant.Subject)
If objVariant.ReminderTime <> "4501-01-01" Then
Debug.Print " strSubject ............: " & strSubject
Debug.Print " objVariant.SentOn .....: " & objVariant.SentOn
Debug.Print " objVariant.ReminderTime: " & objVariant.ReminderTime
If LCase(Item.Subject) = "re: " & strSubject Or InStr(LCase(Item.Subject), strSubject) > 0 Then
'Debug.Print " Item.SentOn .....: " & Item.SentOn
'Debug.Print " objVariant.SentOn: " & objVariant.SentOn
If Item.SentOn > objVariant.SentOn Then
Debug.Print " * strSubject ......: " & strSubject
Debug.Print " * Item.SentOn .....: " & Item.SentOn
Debug.Print " * objVariant.SentOn: " & objVariant.SentOn
If Now > objVariant.ReminderTime Then
With objVariant
' remove flag
.ClearTaskFlag
' attempt to remove reminder
.ReminderSet = False
' reinitializing ReminderTime may have an impact
.ReminderTime = "4501-01-01"
.Save
Debug.Print " ** Flag removed."
Debug.Print " ** Reminder removal attempted."
End With
End If
End If
Else
Debug.Print " *** subject does not match"
End If
End If
End If
Next i
End If
Debug.Print "done"
End Sub
Private Sub test_ToggleMarkAsTaskFlagAndSetReminder()
' for testing
' select a mailitem in the sent items folder to add a flag and a reminder
ToggleMarkAsTaskFlagAndSetReminder ActiveExplorer.Selection(1)
End Sub
Private Sub ToggleMarkAsTaskFlagAndSetReminder(ByVal objItem As Object)
' In my setup
' - TaskDueDate is always 4501-01-01 (no date)
' - Reminders on mailitems are not functional
If TypeOf objItem Is MailItem Then
Debug.Print
Debug.Print "objItem.Subject .............: " & objItem.Subject
Debug.Print " objItem.TaskDueDate Current: " & objItem.TaskDueDate
Debug.Print " objItem.ReminderTime Current: " & objItem.ReminderTime
' https://learn.microsoft.com/en-us/office/vba/api/outlook.olmarkinterval
If objItem.IsMarkedAsTask = False Then
objItem.MarkAsTask (olMarkThisWeek)
Debug.Print " * Marked as task"
' In my setup - TaskDueDate is always 4501-01-01
Debug.Print " objItem.TaskDueDate Updated?: " & objItem.TaskDueDate
Debug.Print " objItem.ReminderTime Updated?: " & objItem.ReminderTime
' In my setup - Reminders on mailitems are not functional
Debug.Print " objItem.ReminderSet Current: " & objItem.ReminderSet
objItem.ReminderSet = True
Debug.Print " objItem.ReminderSet Updated: " & objItem.ReminderSet
objItem.ReminderTime = DateAdd("d", -7, Now) ' testing
Debug.Print " objItem.ReminderTime Updated: " & objItem.ReminderTime
Else 'Reinitialize item
objItem.ClearTaskFlag
Debug.Print " * Task cleared"
' TaskDueDate not functional in my setup, remains 4501-01-01
Debug.Print " objItem.TaskDueDate Updated?: " & objItem.TaskDueDate
objItem.ReminderSet = False
Debug.Print " objItem.ReminderSet = False"
objItem.ReminderTime = "4501-01-01"
Debug.Print " objItem.ReminderTime Updated: " & objItem.ReminderTime
End If
'objItem.Display
objItem.Save
Else
Debug.Print "not a mailitem"
End If
End Sub

Cannot display number values

I just joined and hope to learn all I can here and contribute where I can.
I am having major issues with the last three sections of my VBA script.
The correct, incorrect, and percentage score values are not being displayed on slides 40 & 41.
On slide 42 I cannot get the textbox or the label to display the username, date and their overall percentage score.
Any help on slide 40 would be great and I can workout the rest.
**Sub shapeTextHappySmile()**strong text**
Sub ShapeTextSadSmile()
Sub CertificateBuld()**
Option Explicit
Dim UserName As String
Dim numberCorrect As Integer
Dim numberIncorrect As Integer
Dim numberPercentage As Integer
Dim numberTotal As Integer
Private Sub CertDate()
Dim Rdate As Variant
Rdate = Date
Rdate = Format((Date), "mmmm dd, yyyy")
End Sub
Sub Initialise()
numberCorrect = 12
numberIncorrect = 8
numberPercentage = 58
numberTotal = 20
numberTotal = (numberCorrect + numberIncorrect)
numberCorrect = (numberTotal - numberIncorrect)
numberIncorrect = (numberTotal - numberCorrect)
numberPercentage = Round(numberCorrect / numberTotal) * 100
End Sub
Sub TakeQuiz()
UserName = InputBox(Prompt:="Type Your Name! ")
MsgBox "Welcome To The Academic Online Tutorial Quiz " + UserName, vbApplicationModal, " Academic Online Tutorial Quiz"
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Correct()
numberCorrect = numberCorrect + 1
MsgBox ("Great well Done! That's the correct answer")
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Incorrect()
numberIncorrect = numberIncorrect + 1
MsgBox ("Sorry! That was the incorrect answer")
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub shapeTextHappySmile()
ActivePresentation.Slides(40).Shapes(Label1).TextFrame.TextRange.Text = 12
'numberCorrect
ActivePresentation.Slides(40).Shapes(Label2).TextFrame.TextRange.Text = numberPercentage & "%"
MsgBox "Great Job, Well done " + "," & "Please print a copy of your completion certificate"
MsgBox "After printing or saving a copy of your certificate, you can exit the presentation"
With SlideShowWindows(1).View
.GotoSlide 42
End With
End Sub
Sub ShapeTextSadSmile()
ActivePresentation.Slides(41).Shapes("AnsweredIncorrectly").TextFrame.TextRange.Text = numberIncorrect
ActivePresentation.Slides(41).Shapes("InCorrectPercentage").TextFrame.TextRange.Text = numberPercentage & " %"
MsgBox "Your score was below 70%, in order to pass the quiz and receive a certificate of completion you need to score 70% or more."
MsgBox "Please retake the quiz, and good luck"
With SlideShowWindows(1).View
.GotoSlide 1
End With
' I will add the option of redoing the entire presentation or just the quiz.
'see slide 19 action buttons
End Sub
Sub CertificateBuld()
MsgBox "Great Job, Well done " + "," & "Plese print a copy of your completion certificate"
MsgBox "After printing or saving a copy of your certificate, please exit the presentation"
If numberCorrect >= "14" Then
ActivePresentation.Slides(42).Shapes(" ABCDEFGHIJKLMN ").TextFrame.TextRange.Text = " ABCDEFGHIJKLMN "
ActivePresentation.Slides(42).Shapes("Rdate & Percentage").TextFrame.TextRange.Text = " ON " & Rdate & " WITH A SCORE OF " & numberPercentage & " %"
ActivePresentation.Slides(42).Shapes(UserName).TextFrame.TextRange.Text = UserName
'OR
If numberCorrect <= "14" Then
ActivePresentation.Slides(42).Shapes(8).TextFrame.TextRange.Text = ABCDEFGHIJKLMN "
ActivePresentation.Slides(42).Shapes(9).TextFrame.TextRange.Text = Rdate & " ON " & Rdate & " WITH A SCORE OF " & numberPercentage & " %"
ActivePresentation.Slides(42).Shapes(10).TextFrame.TextRange.Text = UserName
Else
ActivePresentation.SlideShowWindow.View.Save
ActivePresentation.SlideShowWindow.View.Exit
End If
End Sub
See comments inline:
Sub shapeTextHappySmile()
' This won't work:
'ActivePresentation.Slides(40).Shapes(Label1).TextFrame.TextRange.Text = 12
' Shapes have names that are strings, so you need to use .Shapes("Label1")
' Assuming this is an ActiveX label, you get at its properties a bit
' differently from regular PPT shapes, starting with:
' .Shapes("Label1").OLEFormat.Object
' And for a Label ActiveX control, the property you want is .Caption
' And finally, Text/Caption properties take a String value so you want to
' put the 12 in quotes or convert a numeric value to string using Cstr(x)
' Final version:
ActivePresentation.Slides(40).Shapes("Label1").OLEFormat.Object.Caption = "12"
'numberCorrect
' And make the same changes to this one:
ActivePresentation.Slides(40).Shapes(Label2).TextFrame.TextRange.Text = numberPercentage & "%"
' MsgBox "Great Job, Well done " + "," & "Please print a copy of your completion certificate"
' and I think you probably want to do this instead of the above:
MsgBox "Great Job, Well done" & ", " & "Please print a copy of your completion certificate"
MsgBox "After printing or saving a copy of your certificate, you can exit the presentation"
With SlideShowWindows(1).View
.GotoSlide 42
End With
End Sub

Interactive Quiz using ppt

I posted a rubbish question about this before and have gone away and done some work on it to re-ask. Basically I've made a ppt quiz that counts how many correct and incorrect answers a person has given. It then feeds this information back to the user at the end. However what I want to happen now is I want the results to be stored so that I can go back in and see how each user has performed in the quiz. Ideally I would like it to work over 6 networked computers storing all the quiz results in one place. But if need be I can just take a file from each of the 6 computers.
My code so far looks like this:
Dim username As String
Dim numberCorrect As Integer
Dim numberWrong As Integer
Sub YourName()
username = InputBox(prompt:="Type your Name")
MsgBox " Get Ready to begin " + username, vbApplicationModal, " Orange 1C Book 7"
End Sub
Sub correct()
numberCorrect = numberCorrect + 1
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub incorrect()
numberWrong = numberWrong + 1
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Start()
numberCorrect = 0
numberWrong = 0
YourName
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub Results()
MsgBox "Well done " & username & " You got " & numberCorrect & " out of " & numberCorrect + numberWrong, vbApplicationModal, "Orange 1C Book 7"
End Sub'
Any help would be greatly appreciated. Not sure where to begin with the next step.
Here goes one option for you... But some explanation first. This code will create TXT file. Each time someone will reach Results macro it will add results to the file. So, one file will keep all the results until you don't delete them (or the file). Therefore I've added separation line and date/time information for you to easily find appropriate results.
Sub Save_Results_To_Txt()
'set file results location to activepresentation path
'or could be changed to any path string
Dim strWhere As String
strWhere = ActivePresentation.Path
'let's set name of the file separately
Dim strName As String
strName = "\results.txt"
Dim ff As Long
ff = FreeFile
Open strWhere & strName For Append As #ff
Write #ff, Now & vbTab & username
Write #ff, numberCorrect & vbTab & vbTab & numberWrong
Write #ff, String(30, "-")
Close #ff
End Sub
You need to add Save_Results_To_Txt to your Results sub, possibly before MsgBox line.
Your results.txt file will look like:
"2013-04-25 16:11:05 Tom"
"10 11"
"------------------------------"
"2013-04-25 16:11:23 Mark"
"11 10"
"------------------------------"

adding multiple messgeboxes values to single messagebox in vba

I have this code with me where i can display the message when every outer loop ends. I want to catch all these messages in suppose array or soome list like structure and then at the end want to display each of these messages into one msgbox. Would appreciate if someone could help me.
Thanks.
For Each objNavFolder In objNavGroup.NavigationFolders
SkippedItemCounter = 0
If oItems.Count = 0 Then
MsgBox "No Appointments items in " & objNavFolder.DisplayName & "'s folder"
Else
NextRow = NextRow + 1
For Each MyItem In oItems
If MyItem = "" Then
SkippedItemCounter = SkippedItemCounter + 1
End If
'some code here
Next
Set objExpl = _colExpl.Add(objFolder, olFolderDisplayNormal)
NextRow = NextRow - 1
End If
MsgBox "No. of items= "&SkippedItemCounter&"skipped from"&objNavFolder.DisplayName&""
Next
End If
End If
End If
instead of calling msgboxes, create a String and keep adding the messages - at the end of code msgbox(yourString)
for example
decalare a string before the main sub
Dim yourFinalMessage As String ' or Dim yourFinalMessage$
instead of
MsgBox "No Appointments items in " & objNavFolder.DisplayName & "'s folder"
say
yourFinalMessage = yourFinalMessage & vbCrLf & & _
"No Appointments items in " & objNavFolder.DisplayName & "'s folder"
keep doing this until the loop ends.
at the end of loop say
msgbox YourFinalMessage
Not sure to exactly understand what you want, but you might try to add this to a module:
Option Explicit
Dim globalMsg as String
globalMsg = ""
Function customMsg(msg as String)
MsgBox msg
globalMsg = globalMsg & VbCrLf & msg
End Function
Just call customMsg("Your Message") to display a MsgBox and at the end, call MsgBox globalMsg to display all the messages as a single message (one per line). There are a lot of other ways to do this, it depends on you. Please be more explicit if you want any further help.