Consulting

Results 1 to 10 of 10

Thread: VBA MsgBox Width in WIN7

  1. #1
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location

    VBA MsgBox Width in WIN7

    Apologies for no code example. A quick question, for what I admit I have not tried to 'cure' myself.

    Have you noticed that WIN7 seems to chunk in more linefeeds than you would like (for instance, in a path) in the MsgBox?

    If so, have you a workaround?

    Thank you so very much,

    Mark

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    The only way I know of to affect a msgbox appearance is using API and callback functions.
    Be as you wish to seem

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by GTO View Post
    ...Have you noticed that WIN7 seems to chunk in more linefeeds than you would like (for instance, in a path) in the MsgBox?...
    Does my observation ring true for your experience?

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I don't think I've noticed the problem, but I'm not sure I understand the question either

    If you could attach a screen shot, that would help

    Paul

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I use Vista and have not seen it. How many characters are in the path?

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Paul and Ken,

    Apologies for my laziness. XP is accessible to me at work (though the PC in my office is WIN7), I just haven't had the moment free at the same time as the question makes its way through the grey matter.


    Quote Originally Posted by Paul_Hossler View Post
    I don't think I've noticed the problem, but I'm not sure I understand the question either

    If you could attach a screen shot, that would help

    Paul
    Off work now, so only the one laptop (WIN7), unless of course I want to fire up my old fried-keyboard laptop w/XP and Excel2000, which maybe I'll get to later. Anyways, by untrustworthy blond memory, it seems to me that if I had a long enough string without any vbCrLf or vbLF's, of course Windows (or VBA) would wrap it - but... it seems that the MsgBox would get quite a bit wider in XP than in WIN7. Hopefully my question is a bit clearer?

    Here is what I get in WIN7 (on my laptop; I realize that a bigger screen might have some effect):

    ...and here is where I have to admit I do not know how to insert the image mid-post. Anyways, the img at the bottom.


    Quote Originally Posted by Kenneth Hobs View Post
    I use Vista and have not seen it. How many characters are in the path?
    In that one, 104. It breaks at 73. If I use an icon, let us say vbInformation, it looks (I have not run code to measure) to me that the width of the box stays the same and the message text is wrapped sooner (character-count-wise).

    This is what I just tried in a script (.vbs) file. It produces the same. (I didn't really expect different, just tried in case VBA was sending Windows a default width limit of some type.)

            
    MsgBox "This path:" & vblf & _
           "F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro1\MissingFilesAndProcedures.txt" & vblf & _
           "is " & len("F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro1\MissingFilesAndProcedures.txt") & _
           " characters long."
            
    MsgBox "But WIN7 wraps at" & vblf & _
           "F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro" & vblf & _
           "which is " & len("F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro") & _
           " characters long."
            
    WScript.Echo _
           "This path:" & vblf & _
           "F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro1\MissingFilesAndProcedures.txt" & vblf & _
           "is " & len("F:\vbax\MrExcel-767775-help-macro-open-one-files-all-sub-folder-run-macro1\MissingFilesAndProcedures.txt") & _
           " characters long."
    Mark
    Attached Images Attached Images

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    BTW, I just found this: http://www.microsoft-questions.com/m...-in-vista.aspx ...which seems to echo what I am seeing in WIN7.

    Here's in WIN7 (same laptop) with the information icon:
    Attached Images Attached Images

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    In XP; Excel

    they all end up in a fully filled line:

    Sub tst()
        msgbox String(76, "w") & vbLf & String(384, "i") & vbLf & String(96, "A")
    End Sub

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Mark -- your #6 and #7 images look to me at least like the MsgBox max width is reached and then the text is wrapped (not a 'true' line feed)


    Text wrap occurs on my comp with my screen res when I = 40.

    Sub AddMs()
        Dim i As Long
        Dim s As String
        
        s = String(30, "M")
        
        For i = 31 To 50
            s = s & "M"
            Call MsgBox(s, vbOKOnly, "Length = " & i)
        Next i
    End Sub
    Msgbox width increased up to I = 39, and then stays that wide with the text wrapping.

    If there's a LF embedded, that forces a new line of course but the previous text stays wrapped


    Paul

  10. #10
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location

    Chapter: I knew I liked XP; here's yet another reason!

    Well... as one could surmise from the "sub title" if you will - WIN7, and actually from Vista onward, have a major change in MsgBox, as it pertains to how it is rendered width-limit-wise.

    My "discovery" is some years late of course (sort of like washing ashore to a beach in Florida, let's say yesterday, and "discovering" the Americas...) I found several threads about this, nothing in MSDN, but between those threads and here, I am quite sure.

    Thank you Paul and Ken for the comments, and Paul for the testing. Thank you snb for the testing, and yes, the MsgBox forces wrapping at about 2/3 the text intended (in WIN7, and I'm confident in Vista).

    Of course my nag is the same as I spotted in the threads I was able to locate, namely: "Yuck! I used to be able to, for instance, advise the user of the path to let's say, a created workbook. Now any longer string wraps goofy!"

    Again, thank you for your help and just for completeness, here is (in essence, as I happened to include a caption this time) the same MsgBox as at #6, but run in XP. (The other difference that quite frankly, I had never spotted before, is that buttons used to center, but are now right-aligned)

    Mark
    Attached Images Attached Images

Posting Permissions

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