Is it possible to have a time picker content control in Word 2010 that will show the current time when you click on it?

9,423

Yes, you can use TIME field codes. Update each (F9) so that it shows the current time, and then lock it (Ctrl+F11) so that the value doesn't change when you update the other fields in the doc.

If you want some sort of UI element, so that this happens at a mouse click, I just slapped together an extremely crude example, where I inserted one of the legacy ActiveX Command Button controls (on the Developer tab, click Legacy Tools > Command Button), added a space after it, and then inserted a TIME field. I then added this rough bit of code to the button (right-click it, and click View Code) to move focus off the button, move the cursor 2 spaces to the right (into the field), update and lock the field, and then move focus off the field:

Private Sub CommandButton1_Click()
  Selection.MoveRight Unit:=wdCharacter, Count:=2
  Selection.Fields.Update
  Selection.Fields.Locked = True
  Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

Unless someone manually unlocks the field (Shift+Ctrl+F11), each button can be used only once, making it appropriate for a timestamp, which is what it sounds like you're really after. It's not pretty, but perhaps it's a starting point that you can work into something more sophisticated.

Alternatively, since the time doesn't need to update, the Insert tab includes an Insert Date and Time button that can insert a timestamp as static text. You could record a macro of clicking the button and selecting the time format you want. Or, to use a Command Button control again, you could add code like this, which just calls Insert Date and Time to insert the time immediately after the button:

Private Sub CommandButton1_Click()
  Selection.MoveRight Unit:=wdCharacter, Count:=1
  Selection.InsertDateTime DateTimeFormat:="h:mm:ss am/pm", InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, InsertAsFullWidth:=False
End Sub
Share:
9,423

Related videos on Youtube

ShemSeger
Author by

ShemSeger

Updated on September 18, 2022

Comments

  • ShemSeger
    ShemSeger over 1 year

    I want to create multiple time fields that will display the current time when you click on it, but won't update when I update the auto increment fields I'm using in the same document. I need something like the date picker content control. I had hope when I saw you could display the date as h:mm am/pm but it's kind of pointless, because it only ever displays as12:00 AM.

    Is there a way I can get the date picker to show the current time when you click on "today" or is there something else I can do?

    • Porcupine911
      Porcupine911 over 7 years
      Not sure if this meets your needs but how about using a {TIME} Field Code ?
    • ShemSeger
      ShemSeger over 7 years
      @Porcupine911 I tried that, but when I update my other fields, the time fields all update to the same current time.