Mucho Gracias! Works like a charm, and really fast. Here's the code:
VB Code:
'Declarations Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByRef lParam As Any) As Long Private Const EM_GETLINECOUNT As Long = &HBA Private Const EM_LINELENGTH As Long = &HC1 Private Const EM_LINEINDEX As Long = &HBB Private Sub BreakLines(rtb As RichTextBox) Dim i As Long Dim xPos() As Long 'Remove padding rtb.Text = Replace$(rtb.Text, vbCrLf, " ") Do rtb.Text = Replace$(rtb.Text, " ", " ") Loop While InStr(1, rtb.Text, " ") 'Count Lines ReDim xPos(SendMessage(rtb.hwnd, EM_GETLINECOUNT, 0&, 0&) - 1) 'Get Indices For i = 0 To UBound(xPos) xPos(i) = SendMessage(rtb.hwnd, EM_LINEINDEX, i, 0&) Next 'Insert Hard Breaks For i = 1 To UBound(xPos) rtb.SelStart = xPos(i) - 1 + i rtb.SelLength = 1 rtb.SelText = vbCrLf Next End Sub




Reply With Quote