Module 5 - Messages and User Inputs
Lesson 5.1 - Displaying Messages
Topic 5.1.4 - Changing the Title

As well as altering the text displayed on a message box, you can also change its title.  This page describes how to alter the title of a message box.

Alter title

You can change the title of a message box easily enough. Whether anyone will notice is a different matter.

 

Files Needed

You can click here to download the file needed for this part of the lesson.

Completed Code

You can click here to download a workbook which contains the sample code.

Extract and open the workbook linked to in the Files Needed section above.

Changing the Title of a Message Box

By default, a message box running in Excel will display Microsoft Excel as its title. You can change the title of a message box using the sensibly-named Title parameter.  In the workbook you have downloaded, open the VBE and find the subroutine called ChangingTheTitle in Module1.  Edit the code in the subroutine to add a title to the message box:

Edit title

Title is the third parameter of the MsgBox function.

Running the code shown above results in a message box which resembles the one shown below:

Custom title

Ominous, if not particularly informative.

 

If you want to set the title of a message box but not the icon, you can skip the Buttons parameter by typing two commas after the Prompt:

MsgBox "Your Prompt goes here", , "Your Title goes here"

Using Named Parameters

To make it easier to tell what each argument is doing, you can write the name of the parameter before each one.  Find the subroutine called NamingArguments in Module1.  Add the name of the Title parameter to the existing message box and set its value as shown in the code below:

Named arguments

Write the name of the parameter followed by := and then the value you wish to pass to the parameter.

 

If you use named arguments, you can write them in any order and you don't need to use multiple commas to skip optional parameters:

MsgBox Title:="My Title", Prompt:="My Prompt"

To practise customising the title of a message box:

  1. Find the subroutine called CustomisingMessages in Module1.  Add a title to the existing message box (don't forget to provide the name of the parameter):

Sub CustomisingMessages()

 

MsgBox _

Prompt:="Learning never exhausts the mind", _

Buttons:=vbInformation, _

Title:="Inspirational Quote of the Day"

 

End Sub

  1. Run the subroutine to check that it works:
Message with title

Calling a quote "inspirational" doesn't necessarily make it true.

 
  1. Add a second message box to the same procedure which displays a prompt, icon and title (it's up to you whether to use continuation characters and named arguments):

Sub CustomisingMessages()

 

MsgBox _

Prompt:="Learning never exhausts the mind", _

Buttons:=vbInformation, _

Title:="Inspirational Quote of the Day"

 

MsgBox _

Prompt:="So why do I feel so tired?", _

Buttons:=vbQuestion, _

Title:="I'm not sure I agree..."

 

End Sub

  1. Run the subroutine to check that both messages appear the way you expect.
Second message

The second message should resemble this one.

 
  1. Save and close the workbook.
This page has 0 threads Add post