vba text max line length code example

Example: vba text max line length

' Max line length inside a text
Public Function MaxLineSize(ByVal pText As String)
    Dim lines() As String
    Dim line As Variant
  lines = Split(pText, vbCrLf)
    If UBound(lines) - LBound(lines) + 1 = 0 Then Exit Function
    For Each line In lines
        MaxLineSize = Application.Max(MaxLineSize, Len(line))
    Next line
End Function
'--------------------------------------------------------------
Sub TestMe()
	Dim test As String
    test = "aa" & vbCrLf & "bbbbbb"
    MsgBox MaxLineSize(test)       ' 6
End Sub

Tags:

Misc Example