Professional Documents
Culture Documents
You can use the status bar to keep your user informed of the progress of a macro:
The great advantage of status bar messages is that
they do not interrupt your macro the great
disadvantage is that no one tends to notice them!
Application.StatusBar = False
Copyright 2016
Page 25
4.2
Details
Prompt
Buttons
Title
Building Up Messages
You can use the & symbol to concatenate (or join
together) the different parts of a string:
Wise
Wise Owls
Owls
Hint
Hint
Copyright 2016
This is one of the few occasions in VBA when blank spaces matter you
must put a space before and after each & symbol.
Page 26
To get blank lines to appear, specify them as part of the string to be displayed. VbCrLf
stands for Visual Basic Carriage Return Line Feed, if that helps you remember!
Copyright 2016
Page 27
Constant to use
VbOKOnly
Just the
button
OK
VbOKCancel
OK
and
VbAbortRetryIgnore
Abort
VbYesNoCancel
Yes
, No and
VbYesNo
Yes
and
VbRetryCancel
Retry
Cancel
Retry
and
buttons
and
No
Ignore
Cancel
buttons
buttons
buttons
Cancel
buttons
Symbols Available
The four available symbols are:
Symbol
What it means
VbCritical
Critical message
VbQuestion
Question
VbExclamation
Exclamation mark
VbInformation
Information sign
Named Arguments
If you have the time and energy, you can use named rather than positional arguments. The two
subroutines below have identical effect, but the one on the right is much easier to read:
Wise
Wise Owls
Owls
Hint
Hint
Copyright 2016
One big advantage of named arguments you can put them in any order,
and dont need to include comma placeholders if you miss some
arguments out.
Page 28
4.3
You can also use MsgBox as a function to control which buttons a user sees, and to determine
which button a user pressed:
Copyright 2016
Value returned
Actual number
OK
vbOK
Cancel
vbCancel
Abort
vbAbort
Retry
vbRetry
Ignore
vbIgnore
Yes
vbYes
No
vbNo
Page 29
4.4
You can use the InputBox function to ask a user to type something in and then store it:
VariableName = InputBox(Question on input box, Title of input box, Default message)
In this example, we ask the user to type in the
name of a Muppet and then find this on the
worksheet shown on the right.
If you were to type in Miss Piggy, for example, the
macro would display the corresponding colour (Pink).
Wise
Wise Owls
Owls
Hint
Hint
Copyright 2016
You can not customise input boxes. So if you decide that you need an
input box with a pink background, say, you will need to draw and use a
UserForm.
Page 30