Download - INPUT BOX- VBA
![Page 1: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/1.jpg)
Parul Institute Of Engineering & Technology
Subject code:- 151006
Name of subject:- Visual Basic And Application
Name of unit:- Using Intrinsic Dialogs
(Topic):- InputBox
Name of faculty:- 1) Ms.Nupur mam
Name of students:- 1) Vivek Patel (Roll.no- 146)
2) Sagar Pandya (Roll.no-140)
![Page 2: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/2.jpg)
InputBox
Defination: InputBox is used to accept input from the user. An inputBox is a pop up box,similar to a
message box which has a textBox. It also has a “OK” and “CANCEL” buttons.
![Page 3: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/3.jpg)
Syntax:
InputBox(prompt [, title ] [, default ] [, xpos ] [, ypos ] [, helpfile ] [, context ] )
![Page 4: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/4.jpg)
A way to ask a user of your system a question is to use an Inputbox:
Here's what we're trying to achieve: Ask the question:
![Page 5: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/5.jpg)
Display the answer:
![Page 6: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/6.jpg)
Here's the code:
![Page 7: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/7.jpg)
InputBox takes several arguments:PromptTitleDefaultXposYposHelpFileContext
![Page 8: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/8.jpg)
In this example, we have entered:Prompt: "How Many Apples Do You Want?"Title: "Apples"Default: 3
We then display the choice back to the user, but using this in a practical way, we'd trap the answer and use it for something else
![Page 9: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/9.jpg)
We check whether the return from the box is ""
If "" then they've pressed the Cancel button, and we should exit.
![Page 10: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/10.jpg)
Getting User Input With aVBA Input Box
Getting User Input With aVBA Input Box
This could be useful if you wanted to fill up a page with text and print it to see if the margins etc. look OK.
1. Open a new document in Word. 2. Open the VBA Editor (Tools>Macro>Visual
Basic Editor). 3. Copy the following text from Sub
InputBoxInsertText() to End Sub, inclusively.
![Page 11: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/11.jpg)
Sub InputBoxInsertText() Selection.HomeKey wdStory TheSentence = InputBox("Type Text Please", "Using the VBA Input Box") HowManyTimes = InputBox("How many times", "Using the VBA Input Box") For Counter = 1 To HowManyTimes Selection.TypeText TheSentence & " "
Next
End Sub
![Page 12: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/12.jpg)
4. Put the cursor anywhere within this code block.
5. Press F5 6. Type a word or two into the first VBA input
box that appears. 7. Type a number (between 50 and 100) into
the second Input Box.
![Page 13: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/13.jpg)
8. Go to the new document you opened and see how the word or two that you typed into the input box appears repeated the amount of times corresponding to value you entered into the second input box.
![Page 14: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/14.jpg)
ARGUMENT prompt : Required. String expression displayed as the message in the
dialog box. The maximum length ofprompt is approximately 1024 characters, depending on the width of the characters used.
Ifprompt consists of more than one line, you can separate the lines using a carriage return character , a linefeed character , or carriage return–linefeed character combination between each line.
![Page 15: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/15.jpg)
title : Optional. String expression displayed in the
title bar of the dialog box. If you omit title, the application name is placed in the title bar.
Default: Optional. String expression displayed in the
text box as the default response if no other input is provided. If you omit default, the text box is displayed empty.
![Page 16: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/16.jpg)
Xpos: Optional. Numeric expression that specifies, in twips,
the horizontal distance of the left edge of the dialog box from the left edge of the screen.
If xpos is omitted, the dialog box is horizontally centered.
![Page 17: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/17.jpg)
Ypos: Optional. Numeric expression that specifies, in twips,
the vertical distance of the upper edge of the dialog box from the top of the screen.
If ypos is omitted, the dialog box is vertically positioned approximately one-third of the way down the screen.
![Page 18: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/18.jpg)
Helpfile: Optional. String expression that identifies the Help file to
use to provide context-sensitive Help for the dialog box.
If helpfile is provided, context must also be provided.
![Page 19: INPUT BOX- VBA](https://reader036.vdocuments.site/reader036/viewer/2022082811/5590d7811a28ab265d8b461b/html5/thumbnails/19.jpg)