ryantpayton
ryantpayton

Reputation: 405

How to make a message box time out?

When I receive a message in Outlook from a certain group, containing a certain text, I have it run a script.

Sub AutoReply(Item As Outlook.MailItem)
    msg = MsgBox("Would you like to reply to '" & Item.Subject & "' from '" & Item.SenderName & "'?", vbYesNo, "A Helpful Hand")
    If msg = vbYes Then
        GoTo SendEmail
    Else
        GoTo Die
    End If

SendEmail:
    Dim olkReply As Outlook.MailItem
    Set olkReply = Item.Reply
    With olkReply
        .To = "[email protected]"
        .Subject = "RE: " & Item.Subject
        .HTMLBody = "<p style='font-family:calibri;font-size:15px;margin-bottom:.0001pt;color:#1f497d;'>Auto Reply Test</p><p style='font-family:tahoma;font-size:15px;color:#17365d;margin-bottom:.0001pt;'>Test</p>" & olkReply.HTMLBody
        .DeferredDeliveryTime = Date + 0.07
        .Send
    End With
    Set olkReply = Nothing

Die:
    Set olkReply = Nothing
End Sub

When the message box pops up, I want it to go away after 10 seconds if no option is selected. I either want it to cancel or select the option vbNo (GoTo Die).

I updated, but it is throwing an error.

Sub AutoReplyTest(Item As Outlook.MailItem)
    Set objWSH = CreateObject("Wscript.Shell")
    intResult = objWSH.Popup("Would you like to reply to '" & Item.Subject & "' from '" & Item.SenderName & "'?", 10, "A Helpful Hand", vbYesNo)

Select Case intResult
Case 6:
    Dim olkReply As Outlook.MailItem
    Set olkReply = Item.Reply
    With olkReply
        .To = "[email protected]"
        .Subject = "RE: " & Item.Subject
        .HTMLBody = "<p style='font-family:calibri;font-size:15px;margin-bottom:.0001pt;color:#1f497d;'>Test</p><p style='font-family:tahoma;font-size:15px;color:#17365d;margin-bottom:.0001pt;'>Test</p>" & olkReply.HTMLBody
        .DeferredDeliveryTime = Date + 0.07
        .Send
    End With
    Set olkReply = Nothing

Case 7, -1:
    Set olkReply = Nothing
End Sub

Upvotes: 0

Views: 1903

Answers (2)

Rob
Rob

Reputation: 1

If the window is presented for however many seconds and the user does absolutely nothing, it does "automatically" disappear.

Subsequently, in this situation the answer in variable "intresult" is -1 ... it is only another value if the user presses one of the keys e.g.

  • presses the Yes button, then "intresult" = 6
  • presses the No button then "intresult" = 7

Therefore, instead of stating Case 7, -1: instead just state Case -1.

When I used the code which I have adapted for my purpose, I did not need the colon either.

Upvotes: 0

rory.ap
rory.ap

Reputation: 35308

Try this:

Set objWSH = CreateObject("Wscript.Shell")
intResult = objWSH.Popup("Here is my message", 10, "Here is My Title", vbYesNo)

This will show the message for 10 seconds (the second argument). The possible results are:

-1 Timed Out    
1 OK button
2 Cancel button
3 Abort button
4 Retry button
5 Ignore button
6 Yes button
7 No button

Upvotes: 1

Related Questions