PDA

View Full Version : [SOLVED] VBA MsgBox Width in WIN7



GTO
04-04-2014, 04:31 AM
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

Aflatoon
04-04-2014, 04:40 AM
The only way I know of to affect a msgbox appearance is using API and callback functions.

GTO
04-04-2014, 04:48 AM
...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?

Paul_Hossler
04-04-2014, 05:15 AM
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

Kenneth Hobs
04-04-2014, 06:12 AM
I use Vista and have not seen it. How many characters are in the path?

GTO
04-04-2014, 03:10 PM
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.



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.



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

GTO
04-04-2014, 03:23 PM
BTW, I just found this: http://www.microsoft-questions.com/microsoft/VB-Vista-Compatibility/32267907/msgbox-width-limit-in-vista.aspx ...which seems to echo what I am seeing in WIN7.

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

snb
04-05-2014, 06:21 AM
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

Paul_Hossler
04-05-2014, 02:47 PM
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

GTO
04-05-2014, 05:18 PM
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