Programming input and output with VBA
VBA, like Visual Basic Classic, will only run in Windows applications. For simple input and output, we can use two functions:
InputBox
: Displays a string passed into the method, draws a box for the user to enter their response to the prompt, and returns the value enteredMsgBox
: Displays a message box with the string passedin
Simple interaction in VBA
Running the following macro will display an input box that prompts the user for their name and then displays a message box greeting the users:
Sub test() Name = InputBox("What is your name?") MsgBox ("It is nice to meet you " & Name) End Sub
The first line in the code utilizes the InputBox
method to draw an input box for the user to enter their name. The returned value is stored in the variable named Name
. The second line will combine the literal string "It is nice to meet you"
with the value stored in the name variable...