Results 1 to 4 of 4

Thread: customizing msgbox in vba

  1. #1
    Board Regular
    Join Date
    Mar 2016
    Posts
    1,385
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default customizing msgbox in vba

    Hi
    Can I customize msgbox, for example instead of [ok] I change it to [yes]. Thank you very much.

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,770
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: customizing msgbox in vba

    There is a Yes/No and a Yes/No/Cancel option (see this link for all the options: https://docs.microsoft.com/en-us/off...sgbox-function, specifically the buttons argument and all the options they list.)

    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.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,242
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: customizing msgbox in vba

    Quote Originally Posted by Joe4 View Post
    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:
    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
    NOTE
    -----------------
    You can find more information about this by doing a Google search for...

    Excel Dialog Sheets
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  4. #4
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,812
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: customizing msgbox in vba

    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
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •