Change font of Msg Box displayed

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys
When I run the code, a message box is displayed. Is it possible to change the font (size / Bold/ color) of the message displayed in a message box.? If so please share an example.
 
I edited this part too 70 to 75 to make the button more visible as it was partially visible.
Rich (BB code):
                .Height = .LabelMessage.Height + 75                                     ' Height of Message box
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
OK, Like I said, play around with it, see what settings you like best. :)
 
Upvote 0
Ok. I will do some surgery and let you know the final result as I am dreaming of it to be. Thank you Boss.
 
Upvote 0
I edited this part too 70 to 75 to make the button more visible as it was partially visible.

You may find it better to locate the sizing of form & placing of commandbutton in the UserForms Activate event which will negate need to keep specifying it in the calling code. Also, consider limiting max prompt width to keep it manageable on screen

VBA Code:
Private Sub UserForm_Activate()


    Const PromptMaxWidth = 600                                  '< set max prompt width
   
    '-----------------------------------------------------------------------------------
    With Me.LabelMessage
        .AutoSize = True
        .Width = IIf(.Width > PromptMaxWidth, PromptMaxWidth, .Width)   ' Width of Prompt
        .WordWrap = True
    End With
   
    '-----------------------------------------------------------------------------------
     
    With Me.cmdOK
        .Height = 32                                                    'height OKButton
        .Width = 72                                                     'width OKButton
        .Top = Me.LabelMessage.Top + Me.LabelMessage.Height + 15
        .Left = (Me.LabelMessage.Width / 2) + Me.LabelMessage.Left - (.Width / 2)
    End With
   
    '-----------------------------------------------------------------------------------
    Me.Height = Me.cmdOK.Top + (Me.cmdOK.Height * 2) + 10        ' Height of Message box
    Me.Width = Me.LabelMessage.Width + 30                        ' Width of Message box
   
    '-----------------------------------------------------------------------------------
    FormPosition                                                  'center form to screen
End Sub

Sub FormPosition()
'positions form on screen based on its size.
    With Me
      .StartUpPosition = 0
      .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
      .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    End With
End Sub

I have also included a FormPosition code - This is stock code that should centre the form based on your screen size.

Updated Test code

VBA Code:
Sub Test()
'
'-----------------------------------------------------------------------------------
' Message box section
'-----------------------------------------------------------------------------------
        With Form_MessageBox
            .BackColor = RGB(0, 0, 255)                                             ' Background color of Message box ... RGB(0, 0, 255) = Blue
            .BorderColor = RGB(0, 0, 0)                                             ' Set border color ... RGB(0, 0, 0) = Black
            .Caption = Space(110) & "Title of Message Box"                          ' Title for the Message box ... Space command used for centering
'
'-----------------------------------------------------------------------------------
' Text message section
'-----------------------------------------------------------------------------------
            With .LabelMessage
                .BackColor = RGB(255, 255, 255)                                     ' Background color of test message area ... RGB(255, 255, 255) = White
                .Caption = "This is the first line of text." _
                        & vbLf & "This is a second line, if needed, etc."           ' Message(s) to display in the Message area
                .Font = "ArialBlack"                                                  ' Font for Message area
                .Font.Bold = True                                                   '
                .Font.Size = 36                                                     ' Set how big you want the text to be
            End With
            .Show                                                                   ' Show the Message box
        End With
End Sub

Hope Helpful


Dave
 
Upvote 0
Hello JohnnyL.
Regarding inserting the userform in every app to get the customized message box, I am a bit confused. Can you please explain briefly, when I insert the userform, what all should I edit in the properties -Form_Messagebox ? As this is the first time, I am not able to understand it. Just inserting the userform and pasting your code in place of the existing msg box line will show errors unless I edit the properties of Form_Messagebox window.
 
Upvote 0
I tried exporting your form to the new workbook, but was not able to.
 
Upvote 0
A new form = an empty form. That is the problem.

You have to drag the form from the workbook that contains the form to another workbook that you want the form to be put into.

Left click the form and drag it to other workbook.
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,892
Members
449,411
Latest member
AppellatePerson

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