The code that does this in CS:DE is very heavy, I simplified it.

Public Function MakeText(text As String, ChatWidth As Long) As String

    Dim n As Long

    Dim TextWidth As Long, MinText As String

    For n = 1 To Len(text)

        MinText = Mid$(text, n, 1)

        TextWidth = TextWidth + frmMain.TextWidth(MinText)

        If TextWidth > ChatWidth Then

            MakeText = MakeText & vbNewLine

            TextWidth = 0


            MakeText = MakeText & MinText

        End If


End Function

But there is one problem: when it will add a new line, he cuts a letter. I’m leaving, if someone can fix I appreciate it.