View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Is there a Time picker?

You could build one. In a fresh UserForm place a textbox (TextBox1) and try
pasting the below code ...Use up/down arrows to adjust the time


Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "hh:mm")
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'Date and Time Picker Use down/up arrow to change date/time.
Dim intPos As Integer, strType As String
If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3), Array("h", "n"))
Me.TextBox1 = Format(DateAdd(strType, (39 - KeyCode), TextBox1), "hh:mm")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If
End Sub



'For Date and Time picker

Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "dd-mmm-yyyy hh:mm")
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'Date and Time Picker Use down/up arrow to change date/time.
Dim intPos As Integer, strType As String
If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3, 7, 12, 15), _
Array("d", "m", "yyyy", "h", "n"))
Me.TextBox1 = Format(DateAdd(strType, (39 - KeyCode), _
TextBox1), "dd-mmm-yyyy hh:mm")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If
End Sub

--
Jacob


"Barry" wrote:

I've read numerous posts on numerous boards about time formating, none of
which provide a direction to a true time picker.
There are many a date/time picker references. It would seem to be the
answere to many formating questions and would be a life saver to me.

Anyone know of such a bit of code?


Thanks

Barry


.