
This is where the SetFocus method comes in handy. Generally, we would prefer to have the focus return to TextBox1 (the Name input field) after clicking Reset, so that the user can re-enter data without having to explicitly click into the box (or press the tab key several times).

However, since the tab order of CommandButton2 (the Close button) comes after that of CommandButton1 (the Reset button), the form’s focus will move to the Close button after the user presses the Reset button. In the above example, the returned text string is assigned to the MyInput variable before the execution of the code.The Reset button in this form is meant to simply clear all inputs in the text boxes (in case the user makes a mistake), allowing you to re-enter data into these fields.
Vba text box input code#
Now run the above code using the Run button, and we will get the result in a message box, such as:

Step 4: Now give the Prompt as " Your Name", title as " personal information", and Default as " Enter Here". Step 3: Write the word " InputBox", and we will see the syntax of the InputBox. Step 2: Double click on the recently added module and write the macro name, i.e., InputBox_Example.

Step 1: Go to the Visual Basic Editor and insert a new module. To create the InputBox in VBA, follow the below steps, such as: The helpfile must be present if we want to provide the context. This number is assigned to a suitable help topic by the Help author.

It is used to display the string in the title bar of the dialog box. Title (optional parameter): The title is a string expression.If the length of the text is increased, then break the text by using a linefeed character (Chr(10)) or carriage return character (Chr(13)) between each line of the text. The minimum length of prompt is 1024 characters approximately. Prompt (required parameter): This parameter represents a string, and it is used to display as a message in the dialog box.
