General discussion

Locked

command button Excell vba

By dcarrier ·
I am just learning excell VBA and on a command button I am putting in MsgBox lines in VB.I also add a no button in the msgbox.What line would I put in to make the msgbox close when you press the no button?

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

command button Excell vba

by Glen_McLeod In reply to command button Excell ...

The quick answer is:
Unload [formname] (or "Unload Me" if it's the current form)

However, why don't you use the built-in MsgBox statement? It is dismissed automatically when a button is clicked.

Glen

Collapse -

command button Excell vba

by dcarrier In reply to command button Excell ...

Poster rated this answer

Collapse -

command button Excell vba

by Bill_H In reply to command button Excell ...

If you simply want to provide the user with information, use the MsgBox statement. For example:

MsgBox Prompt := "Test Message",Buttons := vbYesNo, Title := "This is only a test..."

This will cause a dialog box to display with a title of "This is only a test...", and containing the string "Test Message"", and a "Yes" and "No" button. If the user clicks on either button the message box dialog will close, *but* you will not be able to determine which button was clicked.

If you wish toknow *which* button was clicked, use the MsgBox function. For example:

Dim iResult As Integer

iResult = MsgBox(Prompt:="Test Message", Buttons:=vbYesNo, Title:="This is only a test...")

This will result in the display of the dialog box asdescribed above. The difference is that a value corresponding to the clicked button is now contained in the variable iResult (iResult will be set to 6 if the "Yes" button was clicked, or 7 if the "No" button was clicked).

The examples above use "named arguments", i.e. the Prompt argument is assigned the string "Test Message". If you use named arguments, the arguments may be in any order. You may also use "positional arguments" as follows:

iResult = MsgBox("Test Message", vbYesNo, "Thisis only a test...")

When you use positional arguments, they must be provided in the proper syntactical order (prompt, buttons, title, helpfile, context).

For further information, view your online help for MsgBox. It is also available on the 'net at:

http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbenlr98/vafctmsgbox.htm

(If the URL above does not work, locate and remove any spaces inserted by the TechRepublic system.)

Hope this helps...

Collapse -

command button Excell vba

by Bill_H In reply to command button Excell ...

(Pursuant to our e-mail discussion...)

The following code will display a succession of message boxes as long as the user clicks on the "Yes" button; if the user clicks on a "No" button, they will be returned to the form containing CommandButton1.

Private Sub Command1_Click()
'This variable indicates which MsgBox button was clicked
Dim iResult As Integer

iResult = MsgBox(Prompt:="test box", Buttons:=4)
If iResult = vbYes Then
iResult = MsgBox("press no to close", Buttons:=4)
If iResult = vbYes Then
iResult = MsgBox("test 3", Buttons:=4)
If iResult = vbYes Then
MsgBox "test 4", Buttons:=4
End If
End If
End If
End Sub

Hope this helps...let me know if you have any more questions.

Collapse -

command button Excell vba

by dcarrier In reply to command button Excell ...

Poster rated this answer

Collapse -

command button Excell vba

by dcarrier In reply to command button Excell ...

This question was closed by the author

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums