O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The InputBox Function

The InputBox function is designed to get input from the user. The most commonly used (but not the complete) syntax is:

	InputBox(prompt [, title] [, default])

where prompt is the message in the input box, title is the title for the input box, and default is the default value that is displayed in the text box. For instance, the code:

	sName = InputBox("Enter your name.", "Name", "Albert")

produces the dialog box in Figure 7-2.

The InputBox function returns the string that the user enters into the text box. Thus, in our example, the string variable sName will contain this string.

An InputBox dialog box

Figure 7-2. An InputBox dialog box

Note that if we want a number from the user, we can still use the InputBox function and simply convert the returned string (such as “12.55”) to a number (12.55) using the Val function, discussed later in this chapter.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required