customizing msgbox in vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
Can I customize msgbox, for example instead of [ok] I change it to [yes]. Thank you very much.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Upvote 0
But I do not believe you can create your own custom options for that in a MsgBox. If you want anything other than the options listed, I think you would need to create your own custom form.
Creating a UserForm would probably be best, but there is a way to create your own "Message Box" although when I used to post it, some of the other volunteers told me there was problems with it. I am not sure what those problems are as I have never had a problem using this technique. With that warning stated upfront, here is a sample programmer created message box to demonstrate the possibilities...
Code:
[table="width: 500"]
[tr]
	[td]Sub MessageBoxAlternative()
  Const SheetID As String = "_Buttonz"
  Dim btnDlg As DialogSheet
   
  Application.ScreenUpdating = False
  On Error Resume Next
  Application.DisplayAlerts = False
  ActiveWorkbook.DialogSheets(SheetID).Delete
  Application.DisplayAlerts = True
  Err.Clear
   
  Set btnDlg = ActiveWorkbook.DialogSheets.Add
   
  With btnDlg
    .Name = SheetID
    .Visible = xlSheetHidden
     
    With .DialogFrame
      .Height = 100
      .Width = 280
      .Caption = "Please confirm..."
    End With
     
    With .Buttons("Button 2")
      .BringToFront
      .Height = 20
      .Width = 60
      .Caption = "Yes, please"
    End With
     
    With .Buttons("Button 3")
      .BringToFront
      .Height = 30
      .Width = 60
      .Caption = "No, thanks"
    End With
     
    .Labels.Add 100, 50, 100, 100
    .Labels(1).Caption = "Are you sure you want to move to the next sheet?"
    Application.ScreenUpdating = True
     
    If .Show = True Then
      MsgBox "Your ''Yes, please'' code goes here", 64, "Yes was clicked"
    Else
      MsgBox "Your ''No, thanks'' code goes here", 64, "No was clicked"
    End If
     
    Application.DisplayAlerts = False
    .Delete
    Application.DisplayAlerts = True
   
  End With
End Sub[/td]
[/tr]
[/table]
NOTE
-----------------
You can find more information about this by doing a Google search for...

Excel Dialog Sheets
 
Upvote 0
Here is a message box with Yes or No
Is this what you want:

Code:
Sub My_Message()
'Modified  10/3/2018  5:08:57 PM  EDT
Dim ans As String
ans = MsgBox("Are your sure you want to do this?", vbYesNo)
If ans = vbYes Then MsgBox "You answered Yes"
If ans = vbNo Then MsgBox "You answered No"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,121
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top