How Can I Increase The Width Of MsgBox?

triptotokyo-5840 36,676 Reputation points Volunteer Moderator
2017-08-11T13:03:16+00:00

At the moment when it displays it's about just under 5cm wide.

I'd like to, say, double that (at least) for all the Message Boxes that I put up.

Thanks in advance for any replies.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2017-08-12T11:52:45+00:00

    trip_to_tokyo

    re: msgbox width

    The Demo sub works for me, as written, and displays the single character "a" 

    To enable a wider msgbox in all code in a single project (not all projects), something like the following should work.

    Note that that the constant "MBcaption" is padded with 15 spaces and

    is declared at the top of a standard module (not a worksheet module).

    MBcaption is used for the caption in all  message boxes.

    If you need different text in other message boxes, you can declare additional constants.

    Personally, I just pad the text or the caption with spaces if I want additional width in a msgbox.

    '---

    Option Explicit

    Public Const MBcaption As String = "ThisHour is:-               "

    Sub ThisIsWorkingForMe()

    Dim ThisHour As Integer

    ThisHour = 9

    MsgBox ThisHour, vbOKOnly, MBcaption

    End Sub

    '---

    Jim Cone

    1 person found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-08-11T17:51:10+00:00

    trip...,

    re:  msgbox width

    Pad the text or caption with spaces.

    Sub Demo()

     MsgBox "a" & VBA.String$(25, 32), vbInformation, "Title"

    End Sub

    '---

    Jim Cone

    Portland, Oregon USA

    https://goo.gl/IUQUN2 (Dropbox)

    (free & commercial excel add-ins & workbooks)

    0 comments No comments
  2. triptotokyo-5840 36,676 Reputation points Volunteer Moderator
    2017-08-11T18:24:18+00:00

    trip...,

    re:  msgbox width

    Pad the text or caption with spaces.

    Sub Demo()

     MsgBox "a" & VBA.String$(25, 32), vbInformation, "Title"

    End Sub

    '---

    Jim Cone

    Portland, Oregon USA

    https://goo.gl/IUQUN2 (Dropbox)

    (free & commercial excel add-ins & workbooks)

    Hi Jim; thanks for that. I'll study it in a bit more detail over the weekend. 

    trip

    0 comments No comments
  3. triptotokyo-5840 36,676 Reputation points Volunteer Moderator
    2017-08-12T11:02:51+00:00

    trip...,

    re:  msgbox width

    Pad the text or caption with spaces.

    Sub Demo()

     MsgBox "a" & VBA.String$(25, 32), vbInformation, "Title"

    End Sub

    '---

    Jim Cone

    Portland, Oregon USA

    https://goo.gl/IUQUN2 (Dropbox)

    (free & commercial excel add-ins & workbooks)

    Hi Jim, I’ve taken a look at what you’ve said but can’t get it to work.

    This is my existing line of code (which works but puts up the wrong width MsgBox):-

    MsgBox ThisHour, vbOKOnly, "ThisHour is:-"

     - where ThisHour is a Variable of Data Type Integer. 

    Sorry; perhaps I should have given you my code in the first place.

    Not only do I want to change the width of the above MsgBox but also the width of any other MsgBox that I may decide to put up.

    Does that make sense?

    Thanks in advance for any replies.

    0 comments No comments
  4. triptotokyo-5840 36,676 Reputation points Volunteer Moderator
    2017-08-13T12:59:47+00:00

    Jim; for the time being for the purposes for which I'm using the code this:-

    Personally, I just pad the text or the caption with spaces if I want additional width in a msgbox.

    • will have to suffice. 

    Many thanks. 

    trip

    0 comments No comments