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
2
votes
1 answer

VBA - Closing or clicking OK in MsgBox from another workbook,

Hi I the following code in Excel VBA, Sub A () Workbooks.open ("A.xls") ActiveWorkbook.Worksheets("1").Select ActiveSheet.CommandButton1.value = true End Sub I'm opening another workbook (the code inside is protected so I can't modify…
lukieleetronic
  • 623
  • 7
  • 10
  • 23
2
votes
2 answers

opening a file that's not in the same directory

I want to run a program (that is not in the same directory as the script) with a MSG box, here's the code (it doesen't work because it needs the program to be on desktop like the script) puls = MsgBox("Want to open steam?", vbYesNo +…
Madknight
  • 23
  • 5
2
votes
2 answers

MSGBOX position in WSH/VBS

here is my next question and i hope some one can help me :-) Is it possible to position a msgbox in wsh/vbs? alt text http://www.4freeimagehost.com/uploads/a9b04cde0527.jpg I need the msgbox everytime in the foreground. I know that how to position a…
Sebastian
  • 494
  • 5
  • 18
  • 34
2
votes
1 answer

vbmsgBox prompt is a mix of RTL(Persian) and LTR(English) but text is displayed in wrong order

I am designing a vba userform for excel 2013, in which I use English and Persian text, the problem is when I use a mix of both languages in a msgBox the bits of text come out in the wrong order, the number is supposed to be displayed at the end.…
2
votes
3 answers

VBS Script - Need to change msgbox to echo

I'm having a hard time converting this script to an echo instead of a msgbox output. I need to output to go into a text file in C:\key.log instead of a message box with the key. Anyone know how to go about this? Thanks! Set WshShell =…
2
votes
1 answer

msgBox is not showing up on successful result

I have the below set up to copy a list and paste to sheet(data). I want it to display a message when it is successful, telling me which row did it started the paste at. However, the errmsg shows instead. Thanks in advance Dim current As String …
Maki
  • 625
  • 4
  • 11
  • 26
2
votes
2 answers

MsgBox function default fourth button

I noticed in VBA that the MsgBox function has a allowable constant of vbDefaultButton4 which will make the fourth button the default. BUT of all the allowable constants for buttons, none give you four buttons. Is there a way to get a fourth button…
Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
2
votes
1 answer

VBA msgbox error

my error is Compile error: expected = msgbox (" Final Score:" & "P1score " & P1 & "P2score " & P2 & "P3score " & P3 & "P4score " & P4,vbOKOnly,"GameOver") I was wondering how to fix this
2
votes
2 answers

VB6 Read String From Resource

I have text file in VB6 Application resources, and I am trying to read the text in it. How to do that? I have been searching for hours without a proper solution. Somebody please help me. My code is: Private Sub Command1_Click() Dim URL As…
user2404495
  • 195
  • 1
  • 6
  • 17
2
votes
3 answers

If #REF! is found then Error Box Macro

I am trying to complete a simple macro that looks for '#REF!' in a worksheet due to a user alterting a row and ruining underlying formulas. I have got as far as the…
Methexis
  • 2,739
  • 5
  • 24
  • 34
2
votes
1 answer

Excel VBA - For next loop - find column number of displayed columns and result stored

This is my first time asking a question, so please bear with me. I have made a macro to hide columns in a named range based on a criteria using FOR-NEXT loop. The result always displays 2 columns. With the resulting 2 columns, I make calculations.…
Mudasser
  • 58
  • 5
2
votes
1 answer

Identify cells in red

The title may be typically simple, but I did not get a solution yet even after researching over several forums on the net. Let me explain the problem. I have an excel workbook where few columns uses if conditions that refers other cells. Based on…
user2341632
  • 49
  • 1
  • 3
  • 9
2
votes
1 answer

Warn the User of empty cell and indicate the location based on values in preceding columns

I am new to VBA. I have a problem which I believe is very simple, but I am failing foolishly. I have to generate a MsgBox warning the user to enter data in blank cells. I also have to mention the destination of the blank cell by indicating the…
2
votes
2 answers

Custom MsgBox without form activate being fired

I have developed a custom MsgBox that works fine in almost every way. The only problem is that when the MsgBox closes the parent form runs the Form_Activate code. A normal MsgBox does not run that code (again). I know i could add a boolean variable…
Martin
  • 1,184
  • 8
  • 24
2
votes
1 answer

VBScript: wait for Excel MsgBox, Click OK

I've written a VBScript that automates a load of processing of Excel workbooks. For some of these workbooks, a MsgBox is triggered when they are opened. This message box is interrupting the automation. Is there a way to listen for this MsgBox in a…
Griffin
  • 13,184
  • 4
  • 29
  • 43