The meaning and uses for ans

P

Pat

When ans = MsgBox "" is used instead of MsgBox "" what is the difference in
the two methods.

Thanks if you can clarify this.
Pat
 
R

Ron de Bruin

Hi Pat

If you use a MsgBox with a OK and Cancel (vbOKCancel)button you can use this

If ans = vbOK Then
'your code
End If

If you hit cancel the code will not run
But if you only want to show the Msgbox you can use only the MsgBox
 
E

Earl Kiosterud

MsgBox can return something based on the buttons the user clicks. If you
don't care what it is, use MsgBox "", If you do, =MsgBox("") returns it,
like:

Response = MsgBox("Click yes or no", vbYesNo)

Variable Response will now be 6 (vbYes, user clicked Yes), or 7 (vbNo, user
clicked no).
 
J

JE McGimpsey

Look at XL/VBA Help ("MsgBox Function"):
MsgBox Function
Displays a message in a dialog box, waits for the user to click a button, and
returns an Integer indicating which button the user clicked.

If you use the first form, ans will be assigned the button-click
integer. With the latter, the integer is thrown away.
 
Top