Share via

Insert Current Time in Textbox

Anonymous
2012-02-02T20:04:32+00:00

How do you write a code to automatically give you the current time once you enter a textbox?  This time should not change as the time does.

Thank you!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-02-03T16:29:55+00:00

In that case create a vba module containing

Option Explicit

Public rngFF As Word.Range

Public fldFF As Word.FormField

Public Sub AOnEntry()

    Dim strCurrentFF As String

    With GetCurrentFF

        .Result = Time

    End With

End Sub

Public Function GetCurrentFF() As Word.FormField

Set rngFF = Selection.Range

rngFF.Expand wdParagraph

For Each fldFF In rngFF.FormFields

    Set GetCurrentFF = fldFF

    Exit For

Next

End Function

Then run the AOnEntry macro on entry to the time field(s). Set the field type to be Date with a time switch to taste.

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-03T14:20:38+00:00

    While I agree with Charles about the better approach you can set a form field's properties to the Current Time to achieve much the same effect - neither requires a macro.

    Was this answer helpful?

    0 comments No comments
  2. Charles Kenyon 167.7K Reputation points Volunteer Moderator
    2012-02-03T13:05:07+00:00

    If you just want a time stamp, you could use a CreateDate field:

    { CREATEDATE /@ " hh:mm:ss" }

    This will give the time the document is created.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-02-03T12:14:46+00:00

    I'm trying to create a log-in sheet by creating a form using MS Word.  What I would like to see is that one of the text form fields give me the current time.  The code would run a macro on entry inside text form field options.  Hope that makes sense. Thank you.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-02-03T07:10:41+00:00

    What sort of a text box?

    Nothing much happens in Word automatically. You will have to force an action. In order to suggest a way forward we need to know what EXACTLY you are trying to do.

    Was this answer helpful?

    0 comments No comments