R
Ron Rosenfeld
Fantastic. Sorry I must have tried Rick's first. This macro works perfectly.
Thanks for all your help!!!!
Oh good. Glad to help. Thanks for the feedback.
I have an improvement to the pattern which you should use for best results.
Please change this line:
re.Pattern = "\s?((\S[\s\S]{1," & W - 2 & _
"}\S)|(\S[\s\S]{" & W - 1 & ",}?\S))(\s|$)"
to this:
re.Pattern = "\b\S.{0," & W - 1 & "}(?=\s|$)|\S{" & W & ",}"
By the way, note that you can change the default value in the InputBox
statement, or even hard code it to the variable and omit having to even see the
InputBox.
Also, note (and this is documented), that if you have a single word that is
longer than desired length, it will not wrap or be truncated. For example, if
you had a maximum line length of 7, and had a word like "totalitarianism", the
word would not wrap, but would be on a line by itself.
--ron