meldrape said:
to cope with punctuation. I haven't tried the example
from the previous post yet.
Here's an example of a string:
TAKE-OFF AND LAYOUTS ARE BASED ON PLANS AND
SPECIFICATIONS PROVIDED. CHANGES AND ADDITIONS ARE THE
RESPONSIBILITY OF THE BUILDER.
Here's a subroutine you can use as a model. I've only tested it a
little bit, though.
'----- start of code -----
Sub ParseWords30(strSource As String)
Dim astrWords() As String
Dim strOut As String
Dim lngA As Long
Dim lngB As Long
astrWords = Split(strSource, " ")
lngA = LBound(astrWords)
Do While lngA <= UBound(astrWords)
strOut = astrWords(lngA)
For lngB = lngA + 1 To UBound(astrWords)
If Len(strOut) + Len(astrWords(lngB)) + 1 > 30 Then
Exit For
Else
strOut = strOut & " " & astrWords(lngB)
End If
Next lngB
lngA = lngB
' Print out the output string in 30-character pieces.
Do Until Len(strOut) = 0
Debug.Print Left(strOut, 30)
strOut = Mid(strOut, 31)
Loop
Loop 'Do While lngA <= UBound(astrWords)
End Sub
'----- end of code -----
In the immediate window, this is what I get:
ParseWords30 "TAKE-OFF AND LAYOUTS ARE BASED ON PLANS AND SPECIFICATIONS
PROVIDED. CHANGES AND ADDITIONS ARE THE RESPONSIBILITY OF THE BUILDER."
TAKE-OFF AND LAYOUTS ARE BASED
ON PLANS AND SPECIFICATIONS
PROVIDED. CHANGES AND
ADDITIONS ARE THE
RESPONSIBILITY OF THE BUILDER.