How to stop timeout?

alee001

Board Regular
Joined
Sep 9, 2014
Messages
154
Office Version
  1. 2010
Platform
  1. Windows
I want to add a option for stop timeout by click on OK button but I don't know how to insert as following code, anyone have idea?
VBA Code:
Private Declare PtrSafe Function MsgBoxTimeout _
    Lib "user32" _
    Alias "MessageBoxTimeoutA" ( _
        ByVal hwnd As LongPtr, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As VbMsgBoxStyle, _
        ByVal wlange As Long, _
        ByVal dwTimeout As Long) _
As Long

Sub btnMsgbox()
Dim q As Byte
    Call MsgBoxTimeout(0, "This message box will be closed after 4 seconds ", "Auto Close MsgBox", vbOKOnly + vbInformation, 0, 4000)
    If q = vbOK Then 'how to stop timeout?
        End
    Else
        Application.Quit
        ThisWorkbook.Close SaveChanges = False
    End If
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this:
VBA Code:
Sub btnMsgbox()
    Dim retVal As Long
    Dim timeout As Single
    timeout = Timer + 4
    retVal = MsgBoxTimeout(0, "This message box will be closed after 4 seconds ", "Auto Close MsgBox", vbOKOnly + vbInformation, 0, 4000)
    If Timer < timeout Then
        MsgBox "OK clicked - timeout stopped"
    Else
        MsgBox "Timeout occurred"
        Application.Quit
        ThisWorkbook.Close SaveChanges:=False
    End If
End Sub
Changes are needed if the timeout crosses midnight.
 
Upvote 0
Solution
It turned out to be as simple as adding a timer, thank you very much for your suggestion.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,047
Members
449,064
Latest member
scottdog129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top