MsgBox

S

Sasa

Im trying to make MsgBox answer condition but it doesnt
work.

Here is the code:

MsgBox "Is this correct?", vbQuestion = vbYesNo
If MsgBox = vbNo Then Exit Sub Else ...

It keeps telling me that "Argument is not optional" and
highlight the second line "MsgBox" word.
I dont understand. I have this code from VBA help. It must
work.

Help is apreciated.

Sasa
 
L

Lin Joyner

You need to store the return value from calling the message box in a
variable and then test that variable on the second line.

Something like the following (untested) code:
Dim response As Integer
response = MsgBox("Correct?", vbYesNo)
If response = vbNo Then
Exit Sub
Else
'do something
End If

Hope this helps!
Lin
 
J

JGM

Hi Sasa,

Look at the help example again... you missed something important,

your code should be something like:

_______________________________________
Dim myMsgBox As Variant

myMsgBox = MsgBox("Is this correct?", vbYesNo)
If myMsgBox = vbNo Then Exit Sub
_______________________________________

You have to declare a variable and assign the MsgBox to that variable. Then
the variable will return the user's interaction with the box...

HTH
Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top