VBA Excel Enter the current date in the text box

I have a dialog box that appears when the user clicks the macro button. This dialog box is mostly populated (date, email address, producer, website, etc.), and all you have to do is enter your name. The problem is that the entered date is static, so if I enter "3/3/11", it will remain so until someone changes it.

I was wondering if there is any way for this text box to always display the current date (unless the user decides to change it for any reason). I tried to put different things in the "Value" section of the text field (for example, "getDate ()" and "= Date ()"), but still have not been successful.

Thank,

Jesse Montermon

+5
source share
7 answers

Use the Initialize event form, for example:

Private Sub UserForm_Initialize()
    TextBox1.Value = Format(Date, "mm/dd/yyyy")
End Sub
+11
source

An easy way to do this is to use the Date function that you want to use in the cell, and the link to that cell from the text field with the LinkedCell property.

From VBA you can try:

textbox.Value = Format(Date(),"mm/dd/yy")
+1
source

, design-timeProperties .

Private Sub UserForm_Activate()
    Me.txtDate.Value = Format(Date, "mm/dd/yy")
End Sub
+1

. UserForm_Initialize():

tbxDate.Value = Date
0

. ,

=Today()      

, , .:)

0

, , .

Sub 
  today_1()
  ActiveCell.FormulaR1C1 = "=TODAY()"
  ActiveCell.Value = Date
End Sub
0

, ,

You can always configure to activate. Now a method is another way. Just an option

Private Sub UserForm_Initialize()

Textbox1.Text = Format(Now(), "mmddyyyhhmmss")

End Sub
0
source

All Articles