Microsoft Office Tutorials and References
In Depth Information
Suppose, however, that you wrote a Sub procedure that takes no arguments, yet you do not want it
listed in the Macros dialog box. You can “hide” it by using the Private keyword:
Private MySub()
End Sub
Now your other macro code will be able to call this Sub, but the user will not be able to execute it
from the Macros dialog box.
Interacting with the User
Sometimes your macro will need to get some information from the user. Perhaps it needs to
prompt for a name, or to get a Yes/No answer. VBA provides two tools for this purpose, MsgBox
and InputBox .
The MsgBox Function
The MsgBox function displays a dialog box with a message and one or more buttons. The
function’s return value indicates which of the buttons the user clicked. You use this function as follows
(I have omitted a couple of optional and rarely used arguments):
MsgBox(prompt, buttons, title)
n prompt is a string expression specifying the message to display in the dialog box.
n buttons is an optional argument specifying what buttons and/or icons to display in the
dialog box and, when there is more than one button, which one is the default (the default
is the one selected if the user presses Enter). If this argument is omitted, only an OK
button is displayed. The possible settings for this argument are given in Table 23.4.
To combine settings, use the Or operator.
n title is an optional argument that specifies the title displayed in the dialog box’s title
bar. If this argument is omitted, the application name is used as the title.
TABLE 23.4
Defined Constants for the MsgBox Function’s buttons Argument
Display OK and Cancel buttons
Display Abort, Retry, and Ignore buttons
Display Yes, No, and Cancel buttons
Search JabSto ::

Custom Search