msgbox title

D

Dick Kusleika

D

No built-in way that I know. This seems to work reasonably well

Sub CenterMsgTitle()

Dim sPrompt As String
Dim sTitle As String

sPrompt = "this is some long, long, long, text"
sTitle = CenteredTitle("The Title", sPrompt)

MsgBox sPrompt, , sTitle

End Sub

Function CenteredTitle(ByVal sTitle As String, _
ByVal sPrompt As String) As String

Dim vLines As Variant
Dim i As Long
Dim lMaxLen As Long

'Title font is slightly larger than prompt font
Const dFontScale As Double = 0.95

'Find the longest line of the message
vLines = Split(sPrompt, vbNewLine)

For i = LBound(vLines) To UBound(vLines)
If Len(vLines(i)) > lMaxLen Then lMaxLen = Len(vLines(i))
Next i

'Add spaces in front of the title
CenteredTitle = Application.Rept(" ", lMaxLen / 2 * dFontScale) & sTitle

End Function
 
Top