none
Preserve line breaks when inserting/pasting from cell to word RRS feed

  • Question

  •  I have the following code 
        

        Dim cant As Integer
        Dim tex As String
        Dim max As Integer
        Dim total As Integer
        Dim final As Integer
        final = 1
        cant = 1
        max = 200 ' this is amount of character that it go have divide, then Visual Basic only allows 250. In this case is 200
         Description = Range("E1").Value
        'Sheets("Programas").Cells(1, 1).Value. This have the string > 250 Caracters, but it divides in cant = 200.
        total = Len(Description) ' this have total characters of the string.
        
        Do While total > (cant) * max
        MsgBox total
            ' this "while" divides string in "cant = 200", example 1200 Characters, this "while" divides the string in 6 parts.
            With wdFind
                    .ClearFormatting
                    .MatchCase = False
                    .MatchWholeWord = False
              
                    .Text = "Here" ' shearch [1] and replace by "cant = 200"
                    tex = Mid(Description, final, max) ' this content "cant = 200" characters, actual
                    .Replacement.Text = tex & "Here"  ' this replace "cant = 200" and finally to add [1],for the next "cant = 200" Characters
                    cant = cant + 1
                    final = max * (cant - 1) ' this have the character actual for to divide in "cant = 200", example ---> 0 position ..... "190 Characteres" other 10 Characters ------ THIS IS FINAL = 200 -------- 201 Character -----> NEXT "cant = 200"
                    .Execute replace:=2
                   ' MsgBox tex & "Here"
            End With
        Loop
      
    With wdFind
                .ClearFormatting
                .MatchCase = False
                .WrapText = True
                .MatchWholeWord = False
                .Text = "Here"
                tex = Mid(Description, final, total)
                .Replacement.Text = tex
                .Execute replace:=2
        End With

    I am looking to preserve newline/breaks in cell description , Is there a way to preserve it ?
    Thursday, November 17, 2016 4:34 PM