18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating UserForms 41<br />

FIGURE 41.2<br />

This dialog box is displayed by VBA’s InputBox function.<br />

The MsgBox function<br />

VBA’s MsgBox function is a handy way to display information and to solicit simple input from users. I use<br />

VBA’s MsgBox function in many of this book’s examples to display a variable’s value. A simplified version of<br />

the MsgBox syntax is as follows:<br />

MsgBox(prompt[,buttons][,title])<br />

The elements are defined as follows:<br />

n prompt: Text that is displayed in the message box. (Required)<br />

n buttons: The code for the buttons that are to appear in the message box. (Optional)<br />

n title: Text that appears in the message box’s title bar. (Optional)<br />

You can use the MsgBox function by itself or assign its result to a variable. If you use it by itself, don’t<br />

include parentheses around the arguments. The following example displays a message and does not return<br />

a result:<br />

Sub MsgBoxDemo()<br />

MsgBox “Click OK to continue”<br />

End Sub<br />

Figure 41.3 shows how this message box appears.<br />

FIGURE 41.3<br />

A simple message box, displayed with VBA’s MsgBox function.<br />

717

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!