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.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
My last post was an example of a simple userform.

VBA Code:
Sub Test()
'
    Dim TestValue   As Long
'
    TestValue = 5
'
    If TestValue = 5 Then
'
'-----------------------------------------------------------------------------------
' 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
'-----------------------------------------------------------------------------------
            .Height = .LabelMessage.Height + 70                                     ' Height of Message box
            .Width = .LabelMessage.Width + 30                                       ' Width of Message box
'-----------------------------------------------------------------------------------
            With .cmdOK
                .Top = .Parent.LabelMessage.Top + .Parent.LabelMessage.Height + 15
                .Left = .Parent.Width - (.Parent.Width / 2) - 21
            End With
'
            .Show                                                                   ' Show the Message box
        End With
    End If
End Sub

Sample workbook here <---

You can adjust the settings as needed. Color settings, Font settings, etc.
 
Upvote 0
The 'If TestValue ...' at the top was just to show how it could be triggered. It has no other significance.
 
Upvote 0
😮 But I remember what I read from your link stating that there is a risk of excel crashing, if I try to use Userform to change the font or color of the message box.
 
Upvote 0
I think you are confused. I think you are referring to a link that used API calls for the code.
This code is just regular excel code/settings.
 
Upvote 0
You mean I can edit and include that in my code and get the required size of the font in my message box.
 
Upvote 0
You mean I can edit and include that in my code and get the required size of the font in my message box.
If you want to.

Play with the sample file so you can see what changes you want to make, when you are done playing with it, then you can decide if you want to use it in your code in place of a regular MsgBox.
 
Upvote 0
The code was the simplest I could think of to accomplish what you mentioned.
 
Upvote 0
But how ? Just insert your code in a new module in my app and what line and where do I need to add in the code to get that.
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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