935 Macros and User Interaction
Hint Try to give your modules unique names. If a module called Tom
has a function called Tom in it, the function Tom will not be available to
the workbook. One common practice is to start module names (and only
module names) with M_.
38.6 Summary
A macro is a VBA user routine used to automate routine or repetitive
operations in Excel. VBA provides two important and very fl exible func-
tions for user interaction: MsgBox and InputBox. VBA groups macros
and functions in units called modules. Keeping related functions and
macros grouped is useful when dealing with large projects. All these
topics, explored in this chapter, will help you in fi nancial programming
in Excel.
Exercises
1. Write a macro that displays the following message box. The message box should be
on top of all other windows, and it should prevent the user from doing anything in
any application until one of the buttons is clicked.
Hint You need to use some options of MsgBox that were not covered in the text.
Use the VBA Help system.
2. Write a present-value calculator macro similar to the one that appears in section
38.4. However—as illustrated here—your macro should ask the user for the cash
fl ow value, the interest rate, and the number of periods. It should then display the
result in a message box. Sensible default values should be supplied for all arguments.
Do not use the Excel function PV; write your own present value function and use
it. A reminder:
PV CF r n
CF
r
i
i
n
(,,)
()
=
+
=
∑
1
1