First, take a look at Debra Dalgleish's site:
http://www.contextures.com/xlUserForm01.html
Just to get familiar with working with userforms.
The when you're done, try creating a userform (named userform1) that
contains a
textbox (to get the input), a label (just for error messages) and two
buttons
(cancel and ok).
Then in a general module, put this:
Option Explicit
Public RunWhen As Double
Public myVal As Variant
Public myDefaultValue As Long
Dim UF1 As UserForm1
Sub testme()
Set UF1 = New UserForm1
UF1.Show
Select Case LCase(myVal)
Case Is = "timedout"
myVal = myDefaultValue 'some default
Case Is = "cancel"
myVal = 0 'what to do if user cancelled
'exit sub '????
Case Else
myVal = CLng(myVal)
End Select
MsgBox myVal
End Sub
Sub KillForm()
myVal = "TimedOut"
Call KillTimer
Unload UF1
End Sub
Sub KillTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:="killForm", schedule:=False
On Error GoTo 0
End Sub
Then behind the userform, put this code:
Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
myVal = "Cancel"
Call KillTimer
Unload Me
End Sub
Private Sub CommandButton2_Click()
Call KillTimer
If IsNumeric(Me.TextBox1.Value) Then
myVal = Me.TextBox1.Value
Unload Me
Else
Me.Label1.Caption = "Please enter a number"
End If
End Sub
Private Sub TextBox1_Change()
If blkProc = True Then
Exit Sub
Else
Call KillTimer
End If
End Sub
Private Sub UserForm_Initialize()
RunWhen = Now + TimeSerial(0, 1, 0) 'hr,min,sec
Application.OnTime RunWhen, "KillForm"
Me.Label1.Caption = ""
myDefaultValue = 4 'or whatever you want
blkProc = True
Me.TextBox1.Value = myDefaultValue
blkProc = False
End Sub
You'll get 3 different types of answers from the userform--Cancel (if the
user
hit the cancel button), TimedOut (if the form times out) or a number.
I wasn't sure what to do if the user cancels.
You can read more about the scheduling procedures at Chip Pearson's site:
http://www.cpearson.com/excel/ontime.htm
=======
For testing purposes, you may want to use something smaller than a minute.
And this procedure kills the timer if the user clicks on a button or
starts
typing in the textbox.