Consulting

Results 1 to 5 of 5

Thread: MessageBox line length

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    MessageBox line length

    Hi Folks

    Since there is no option to format message boxes, I was wondering if there if a way to find the maximum number of characters before Excel does a line break in a messagebox. Apparently that number varies depending on the excel version and/or screen resolution, but I'm not sure about that. I can only tell that the number of characters for a single line varies depending on the screen and/or office version. For example, oddly enough, the standard company screen (i.e. around 19", Win8, Excel 2013) shows less line breaks than my personal PC (Win10, Excel 2016, and high resolution) for the same message.

    The reason for that is that I'd like to set the length of a splitter line (consisting of underscores) in order to make a larger, multi-line message more readable.

    Any ideas?
    Last edited by nikki333; 03-08-2019 at 11:42 AM.

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi nikki333

    max no per line = 85
    Maxium amount of chars = 1024
    That depends on sixe of chars as well so might be less

  3. #3
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    thank you Rob

    Using the standard font setting, i got a break at 79 -------

  4. #4
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    No problem
    Have you thought about creating a user form with a textbox, then you can format it the way you want.

  5. #5
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    7,337
    Location
    I had to do a couple of fairly large applications and wanted the message boxes to look 'special'

    You can look at the attached which use a user form as a display, but I added options, etc to avoid re-inventing the wheel and to keep things looking the same

    You could customize the user form using the standard UF tools to add a logo or lables, etc.

    Capture.JPG

    Option Explicit
    Sub test()
        
        'the ^ equals vbLfCr and the ` equals vbCLf & vbTab
        Call msgInformation("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
        Call msgWarning("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
        Call msgCritical("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
    
    
        'vbYes = 6, vbNo = 7
        MsgBox msgContinueOrNot("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
        MsgBox msgContinueOrNot("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333", False)
        
    
        'vbYes = 6, vbNo = 7
        MsgBox msgYesOrNo("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
        MsgBox msgYesOrNo("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333", False)
    
        'vbAbort = 3, vbRetry = 4, vbIgnore = 5
        MsgBox msgAbortRetryIgnore("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333")
        MsgBox msgAbortRetryIgnore("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333", vbRetry)
        MsgBox msgAbortRetryIgnore("AAAA bbbbbbbbbbbbbb cccccccccccccccc^^ddddd eeeeeeeeeeeee fffffffff`11111111`2222222`3333333", vbIgnore)
    
    
        'example of real world
        If msgYesOrNo("File not there!!!^^Keep on going?") = vbNo Then
            MsgBox "OK, stopping"
        Else
            MsgBox "OK, I'll look for it"
        End If
        
    End Sub
    
    Attached Files Attached Files
    Last edited by Paul_Hossler; 03-09-2019 at 08:43 PM. Reason: Better version of XLSM
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •