Textbox Time

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
I have the following script but only want the hh:mm:ss not the whole date and time, can someone please help with this.

So it would be i.e. 15:33:20


Code:
With UserForm1.TextBox1
.Text = Left(.Text, .SelStart) & Format(timeStamp, "m-dd h:mm:ss am/pm") _
& Mid(.Text, .SelStart + 1)
End With
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try:
Code:
.Text = Format(timeStamp, "h:mm:ss")
 
Upvote 0
Hi Misca,

For some reason that script doesn't work as now the textbox is empty, yet when I use the old script the old script works except for being extended time/date.
 
Upvote 0
I found a code that works, Thanks for your help Misca.

Code:
 Dim strTime As String
    strTime = Format$(Now(), "hh:mm:ss")    
   UserForm1.TextBox1.Value = strTime
 
Upvote 0
Can you please show the whole code and where you would post it

Bernie
 
Upvote 0
Insert a userform named clock1 with a textbox and a label.

Insert the following code into your userform (userform is captionless but movable)

Code:
Dim myClipbd As New DataObject
Private m_sngX As Single
Private m_sngY As Single

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 1 Then
m_sngX = X
m_sngY = Y
End If
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 1 Then
Me.Left = X + Me.Left - m_sngX
Me.Top = Y + Me.Top - m_sngY

End If
End Sub

Private Sub Label1_Click()
Call EndTimer
Me.Hide
End Sub

Private Sub UserForm_Activate()
 Call RemoveCaption1
 Clock1.Top = 100
Clock1.Height = 40
Clock1.Width = 120
Dim strTime As String
    strTime = Format$(Now(), "h:mm:ss am/pm")
  Clock1.TextBox1.Value = strTime

End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Call EndTimer
End Sub
Insert the following code into a module

Code:
Sub ClockShow()
    
    Call StartTimer
   Clock1.Show vbModeless
   
End Sub
Insert the following into it's own separate module.

Code:
Option Private Module
'Returns the Window Handle of the Window
'that is accepting User input.
 Public Declare Function GetForegroundWindow _
   Lib "user32.dll" () As Long

 Private Declare Function GetWindowLong _
  Lib "user32.dll" _
    Alias "GetWindowLongA" _
     (ByVal hwnd As Long, _
      ByVal nIndex As Long) As Long
               
 Private Declare Function SetWindowLong _
  Lib "user32.dll" _
    Alias "SetWindowLongA" _
     (ByVal hwnd As Long, _
      ByVal nIndex As Long, _
      ByVal dwNewLong As Long) As 0

'Redraw the Icons on the Window's Title Bar
 Private Declare Function DrawMenuBar _
   Lib "user32.dll" _
    (ByVal hwnd As Long) As Long

 Private Const GWL_STYLE As Long = (-16)
 Private Const WS_CAPTION = &HC00000

Sub RemoveCaption1()

  Dim BitMask As Long
  Dim hwnd As Long
  Dim WindowStyle As Long
  
    hwnd = GetForegroundWindow
    WindowStyle = GetWindowLong(hwnd, GWL_STYLE)

    BitMask = WindowStyle And (Not WS_CAPTION)

    Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
    Call DrawMenuBar(hwnd)
   
End Sub
Insert the following into it's own separate module

Code:
Public Declare Function SetTimer Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal nIDEvent As Long, _
    ByVal uElapse As Long, _
    ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single

Sub StartTimer()
    TimerSeconds = 1 ' how often to "pop" the timer.
    TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
    On Error Resume Next
    KillTimer 0&, TimerID
End Sub



Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _
        ByVal nIDEvent As Long, ByVal dwTimer As Long)
    
    ''''''
    ' This procedure is called by Windows. Put your
    ' code here.
    ''''''
    Dim strTime As String
    strTime = Format$(Now(), "h:mm:ss am/pm")
  Clock1.TextBox1.Value = strTime
    
    
End Sub
Now call your macros and click on clockshow, you will need to adjust the colors on your userform etc... and the size of the textbox, my textbox is 21h x 88w and label is 12h x 10w and only has an X in it's caption.

The userform color is black and the textbox forecolor is green.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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