Questions tagged [msgbox]

The MsgBox function is used in Visual Basic to display a dialog box to the user, wait for a button to be clicked and return the result to the caller. Use this question for using MsgBox specifically; for the .NET MessageBox class, use the "messagebox" tag instead.

Summary

The MsgBox function is exclusive to the Visual Basic programming language. It is commonly used in , or Visual Basic for Applications (), but can also be used in Visual Basic .NET for backwards compatibility. (However, in , it is recommended to use the MessageBox class from the .NET Framework instead.)

Function signature

As listed on MSDN:

Public Function MsgBox( _
   ByVal Prompt As Object, _
   Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OKOnly, _
   Optional ByVal Title As Object = Nothing _
) As MsgBoxResult
  • Prompt is used to set the text you want to display in the dialog box.
  • Buttons is used to set which buttons are displayed in the dialog box. If omitted, only the OK button is shown by default.
  • Title is used to set the title text for the dialog box. If omitted, the application name is displayed by default.

The return value is a numeric value indicating what action the user took in response to the dialog (i.e., which presented button was clicked).

Related tags

Useful questions

Links

403 questions
4
votes
4 answers

Message alert other than MsgBox in Excel?

Is there another way to display messages in Excel other than the MsgBox? I was thinking of the security alert/enable macros alert style. Can I use that same space to display some text? I am trying to notify users without them needing to click a…
Moritz Schmitz v. Hülst
  • 3,229
  • 4
  • 36
  • 63
3
votes
2 answers

How to change MsgBox message caption at runtime?

I need to change the default caption of a MsgBox message box at runtime. Currently it constantly shows the value of the SetupAppTitle directive as a caption: [Setup] SetupAppTitle=myAppName But this is specified at compilation time. How to do this…
user1254203
3
votes
1 answer

How to correctly add "yes / no" into a VBA message box with existing string

I have a macro that runs based on a drop down list. There are three options in the drop down list. I have created a custom warning message for each drop which works well. I wanted to add a "YES" and "NO" button selection onto this code, but i can't…
3
votes
2 answers

display a 2 row message pop -up vba 6

is there a way to display a 2 or 3 or 4 or n line message on a pop-up window in vba 6 ? For the moment my pop-up window ( calling the MsgBox function) displays the message like this : You did something wrong. Please enter valid input. and I…
Radu Puspana
  • 115
  • 1
  • 4
  • 12
3
votes
2 answers

Yes/No message box always returns yes - VB.Net

I was experimenting with message boxes, and tried a simple yes/no messagebox So I wrote this simple piece of code. However, the "chc" variable always returns as 1, no matter what button I press. I provided the code, so you maybe see what I did…
Null_
  • 33
  • 1
  • 4
3
votes
5 answers

Display popup for a time period in Excel

I am trying to generate a popup that closes after a given WaitTime in seconds. I consulted this link and this link. I tried to apply the method from "VBA Excel macro message box auto close"; my code is the following: Sub TestSubroutine() Dim…
Daneel Olivaw
  • 2,077
  • 4
  • 15
  • 23
3
votes
4 answers

MessageBox.Show not raising HelpRequested event

I have a form that is showing a MessageBox using MessageBox.Show, and trying to receive events from the Help button on the MessageBox so I can execute my own code. The Microsoft documentation shows how to do this; however, using what is suggested…
Trevortni
  • 688
  • 8
  • 23
3
votes
4 answers

Timeout Msgbox popup

I have a small script that runs (basically fires a msgbox to tell people that their account passwords are about to expire). I want it to close itself after say 30 minutes, but cannot get the syntax right to do it, can anyone help? Below is the…
Gavin
  • 33
  • 1
  • 1
  • 4
3
votes
2 answers

Is it possible to put a combo box (drop down list) in a MS Access MsgBox?

There is a combo box (dropdown list) with a list of revenue types. If the user types into the box a value that is not part of the list, a msgBox pops up and asks them if they want to add that value to the list. Here is my problem: In that msg box, I…
dmr
  • 21,811
  • 37
  • 100
  • 138
3
votes
1 answer

MsgBox Appears multiple times...reaarange macro so it is only displayed once

I have a script that looks through an entire column and looks for values between 1 - 9, if it encounters a number it throws a message box if it doesnt it currently throws 10 message boxes, I know this is because the second box is still incide the…
Methexis
  • 2,739
  • 5
  • 24
  • 34
3
votes
2 answers

VB.NET MsgBox Yes only works the second time?

So this is my code below. When I click the X button on the form, the message box shows and clicking no works but when I click yes, the message box closes and comes up again quickly and then the second time, clicking either button will close the…
zxzxzx
  • 33
  • 1
  • 1
  • 9
3
votes
10 answers

How do I close a currently opened MsgBox using VBA?

Is there any option to close the currently opened MsgBox using any code in VBA access form application?
Jaison
2
votes
5 answers

How to auto close VBScript thousands of MsgBox's

I have a rogue vbscript that went a little crazy tracing output and now I have thousands of message boxes to close. I can hold down the Enter key and close lots of them but that still takes several minutes. I could reboot but then I have to open…
Jeremy E
  • 3,704
  • 2
  • 28
  • 46
2
votes
1 answer

How to create a Message-Box in Google Apps Script

I am creating an new Google Apps Script about GDrive/New/More/Google Apps Script. The script is running perfect and on the end my intention is to send a Info on the Desk. When I am using this line: Browser.msgBox("TEST"); I get the error…
J. Doe
  • 151
  • 12
2
votes
2 answers

Displaying an image in a VBScript MsgBox

How can I display an image in a MsgBox?
angel
  • 73
  • 1
  • 4
  • 8
1
2
3
26 27