Message Box Functions in VB

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Hi there everyone,

This is probably a really easy one to answer...

I've been adding in message boxes to my macros to prompt a response from the user however some message boxes will contain a bit of text information before the initial prompt question, how do I get this to show on two separate lines and centred in the message box...

Code:
Dim Ans As Integer
    Ans = MsgBox("You are about to produce the Monthly Illness & Absence Report for Bancassurance Telephony." & vbCrLf & "Do you wish to continue?", vbYesNo)
    Select Case Ans
        Case vbYes '

Thanks in advance,

Andy

PS - if anyone knows of any decent tutorial websites that deal with the basics of VB that would help and stop me from asking daft questions :oops:
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Unfortunately, there is no built-in way to center the text on a msgbox. You can add spaces to move the text over to *appear* centered, though.

As for multiple lines: use a line feed. For example:

Code:
Msgbox "This is line 1." & vbCrLf & "This is line 2."

You could also use either Chr(10) or vbNewLine in place of vbCrLF. All three do the same thing :)
 

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
Try it this way:
Code:
MsgBox "You are about to produce the Monthly Illness & Absence Report for Bancassurance Telephony." & Chr(13) & "Do you wish to continue?", vbYesNo
 

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Yeah after twenty minutes of playing around with it I figured out there was nothing I could about this apart from adding in spaces. Thanks for the workaround guys!
 

Forum statistics

Threads
1,136,271
Messages
5,674,746
Members
419,525
Latest member
helensesc

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
Top