Parul Institute Of Engineering & TechnologySubject code:- 151006Name of subject:- Visual Basic And ApplicationName of unit...
InputBox Defination:   InputBox is used to accept input from the user.   An inputBox is a pop up box,similar to a    me...
   Syntax:   InputBox(prompt [, title ] [, default ] [, xpos ]    [, ypos ] [, helpfile ] [, context ] )
   A way to ask a user of your system a question    is to use an Inputbox:   Heres what were trying to achieve:   Ask t...
   Display the answer:
   Heres the code:
   InputBox takes several arguments:      Prompt      Title      Default      Xpos      Ypos      HelpFile      Co...
   In this example, we have entered:      Prompt: "How Many Apples Do You Want?"      Title: "Apples"      Default: 3...
We check whether the return from the box is""   If "" then theyve pressed the Cancel   button, and we should exit.
Getting User Input With aVBA Input Box   This could be useful if you wanted to fill up a    page with text and print it t...
   Sub InputBoxInsertText()     Selection.HomeKey wdStory     TheSentence = InputBox("Type Text Please", "Using    the VB...
   4. Put the cursor anywhere within this code    block.   5. Press F5   6. Type a word or two into the first VBA input...
8. Go to the new document you opened and seehow the word or two that you typed into theinput box appears repeated the amou...
ARGUMENT prompt :   Required.   String expression displayed as the message in    the dialog box. The maximum length    ...
 title   :   Optional. String expression displayed in the    title bar of the dialog box. If you omit title, the    appl...
 Xpos:   Optional.   Numeric expression that specifies, in twips,    the horizontal distance of the left edge of the   ...
 Ypos:   Optional.   Numeric expression that specifies, in twips,    the vertical distance of the upper edge of the    ...
 Helpfile:   Optional.   String expression that identifies the Help file to    use to provide context-sensitive Help fo...
INPUT BOX- VBA
Upcoming SlideShare
Loading in …5
×

INPUT BOX- VBA

1,239 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,239
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

INPUT BOX- VBA

  1. 1. Parul Institute Of Engineering & TechnologySubject code:- 151006Name of subject:- Visual Basic And ApplicationName of unit:- Using Intrinsic Dialogs(Topic):- InputBoxName of faculty:- 1) Ms.Nupur mamName of students:- 1) Vivek Patel (Roll.no- 146) 2) Sagar Pandya (Roll.no-140)
  2. 2. 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.
  3. 3.  Syntax: InputBox(prompt [, title ] [, default ] [, xpos ] [, ypos ] [, helpfile ] [, context ] )
  4. 4.  A way to ask a user of your system a question is to use an Inputbox: Heres what were trying to achieve: Ask the question:
  5. 5.  Display the answer:
  6. 6.  Heres the code:
  7. 7.  InputBox takes several arguments:  Prompt  Title  Default  Xpos  Ypos  HelpFile  Context
  8. 8.  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, wed trap the answer and use it for something else
  9. 9. We check whether the return from the box is"" If "" then theyve pressed the Cancel button, and we should exit.
  10. 10. 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.
  11. 11.  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
  12. 12.  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.
  13. 13. 8. Go to the new document you opened and seehow the word or two that you typed into theinput box appears repeated the amount of timescorresponding to value you entered into thesecond input box.
  14. 14. 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
  15. 15.  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.
  16. 16.  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.
  17. 17.  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.
  18. 18.  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.

×