Message Boxes (MsgBox) and Input Boxes (InputBox) in Excel
|
613-749-4695 (Peter) |
Tips and Ideas on Excel |
Tips and Ideas on Macros |
VBA Chapter 16 of 24: Message Boxes (MsgBox) and Input Boxes in ExcelVBA for Excel Code for Message Boxes MsgBoxIn VBA for Excel the message box (MsgBox) is the primary tool to interact with the user. You can use it to inform, alert him or ask him to choose a certain path (Yes/No).
The code in VBA for Excel to generate the following basic message box is:
When you develop a procedure that takes time to run, you end your code with a basic message box telling the user that the procedure has been executed. Notice that if you want part of your message to be between quotation marks you have to double the quotation marks within the message. When you develop a VBA procedure that will do something important like delete all data always start the code with a message box that asks the user if he is certain that he wants the procedure to run. In this case you will use a "Yes/No" message box. Excel VBA Input BoxesInput boxes are used to require a SINGLE value from the user but it has many limits that will drive you to use VBA userforms instead.
VBA for Excel Code for Input BoxesThe basic code for an input box is as follow. With the following procedure whatever value submitted by the user is entered in cell "A1" of a sheet named "Intro" . You can also use a different header instead of "Microsoft Excel" for the input box like "Please answer this question." in this example: Sheets("Intro").Range("A1").Value = InputBox("For what year do you need this report?" , "Please answer this question.")
Before we go on I must tell you that it is not possible to impose the password character (*) in the input box. To achieve this you must work with a userform and a text box. See how in the section on userforms and controls See 20 message boxes with dynamic messagesincluding: the vbQuestion, the vbInformation, the vbExclamation or the vbCritical message boxes and how it is done in "vba-tutorial-message-boxes.xls" |
Next Chapter: VBA for Excel Code for Databases and Filters |
VBA Table of Contents |
Discover Even More in 50 Excel spreadsheets |
|
613-749-4695 (Peter) |
Tips and Ideas on Excel |
Tips and Ideas on Macros |
Message Boxes (MsgBox) and Input Boxes in Excel