Hi,
I have found this code on the internet but I don't know how to make it to funtion.
Can anyone tell me what do I have to add in the beggining and in the end to make it work.
Thank you!
Function SplitText(str As String, iPart As Byte, iMaxChars As Integer) As String
' ______________________________________________________________________________
' | |
' | Wim Gielis |
' | wimmekegielis@hotmail.com |
' | 06/09/2007, revised 06/10/2007 |
' | Custom function to split text in parts. Words are not broken, and you |
' | can specify the maximal number of characters in each part |
' | Also on http://www.wimgielis.be |
' |______________________________________________________________________________|
Dim arrWords As Variant
Dim iWordCounter As Integer
Dim j As Integer
Dim iPartCounter As Integer
Dim sConcatTemp As String
If iPart < 1 Then
SplitText = "Part number should at least be 1"
Exit Function
End If
SplitText = ""
If str <> "" Then
str = Trim(str)
str = Replace(Replace(str, Chr(32), " "), Chr(160), " ")
str = Replace(str, " ", " ")
arrWords = Split(str)
ReDim Preserve arrWords(UBound(arrWords) + 1)
arrWords(UBound(arrWords)) = "a" 'dummy to avoid an error message later on
iPartCounter = 1
j = 0
Do While iPartCounter <= iPart
iWordCounter = 0
sConcatTemp = ""
Do While Len(sConcatTemp) - 1 <= iMaxChars And j + iWordCounter < UBound(arrWords)
sConcatTemp = sConcatTemp & " " & arrWords(j + iWordCounter)
iWordCounter = iWordCounter + 1
Loop
If Len(sConcatTemp) - 1 > iMaxChars Then iWordCounter = iWordCounter - 1
If iPartCounter = iPart Then
If Len(sConcatTemp) - 1 > iMaxChars Then
SplitText = Trim(Left(sConcatTemp, Len(sConcatTemp) - Len(arrWords(j + iWordCounter))))
Else
SplitText = Trim(sConcatTemp)
End If
End If
iPartCounter = iPartCounter + 1
If j + iWordCounter = UBound(arrWords) Then Exit Function
j = j + iWordCounter
Loop
End If
End Function
Bookmarks