Search code examples
vbams-wordtextboxdefaultuserform

How do I add a variable as a default in a UserForm text box?


In word vba, I have developed a UserForm with two text boxes. For one of the text boxes I would like to add, as a default, a string variable that has already been defined and is calculated just before the form is displayed. If textbox is "TextBox1" and the default string is "NewWord", how can I code this?


Solution

  • Assign the value in the Initialize event:

    Private Sub UserForm_Initialize()
    
        Me.TextBox1.Text = "Default text to be displayed when the form is loaded."
    End Sub