I have created a UserForm1 in Excel and saved it as an add-in. This add-in works fine but it does not store some data that I need (does not store it in itself not in the opened excel). I have to store some information in cells A1 and A2 (in A1 Username, in A2 today's date).
When I run this add-in the UserForm1 does not contain these values.
Is there a way how I can store the UserName and get the updated date?
Here is the code for UserForm1:
Private Sub UserForm1_Initialize()
Me.DocumentName.Text = ActiveWorkbook.FullName
DocumentName.Visible = False
TextBoxDate.Value = Worksheets("Sheet1").Cells(2, "A").Value
TextBoxDate.Value = CDate(TextBoxDate.Value)
UserName.Visible = False
Userform1.UserName.Text = CStr(Range("A1").Value)
'If A1 is empty pops up a UserRegister form
If UserName = "" Then
UserRegister.Show
End If
End Sub
UserRegister form code:
Private Sub UserName_Change()
Sheets("Sheet1").Range("A1") = UserName.Text
End Sub
' I want to store the UserName, so the user does not have to enter it every single time
Private Sub CommandButtonGO_Click()
ThisWorkbook.Save
Unload Me
End Sub
To get the date I just use the formula =TODAY() in Cell A2. I know there are other ways, but I found this one very simple.