Function UnWrap(strText) Dim strWhiteChars, strLineEndPunctuation, strChar strLineEndPunctuation = ".,"",!,?,',)" 'comma delimited list of characters at the end of a sentence strWhiteChars = " " & "," & Chr(160) & "," & vbTab 'comma delimited list of whitespace characters 'Normalize line ends strText = Replace(strText, vbLf, vbCr) Do While Instr(strText, vbCr & vbCr) <> 0 : strText = Replace(strText, vbCr & vbCr, vbCr) : Loop strText = Replace(strText, vbCr, vbCrLf) 'Trim leading and trailing spaces (which also empties lines that only have whitespace) For Each strChar In Split(strWhiteChars, ",") Do While Instr(strText, vbCrLf & strChar) <> 0 strText = Replace(strText, vbCrLf & strChar, vbCrLf) Loop Do While Instr(strText, strChar & vbCrLf) <> 0 strText = Replace(strText, strChar & vbCrLf, vbCrLf) Loop Next Do While Instr(strText, vbCrLf & vbCrLf) <> 0 : strText = Replace(strText, vbCrLf & vbCrLf, vbCrLf) : Loop 'Remove hyphens at line ends, rejoining the split words strText = Replace(strText, "-" & vbCrLf, "") 'Disallow newlines unless they occur at the end of a sentence For Each strChar In Split(strLineEndPunctuation, ",") strText = Replace(strText, strChar & vbCrLf, strChar & "§") Next Do While Instr(strText, vbCrLf) <> 0 : strText = Replace(strText, vbCrLf, " ") : Loop Do While Instr(strText, " ") <> 0 : strText = Replace(strText, " ", " ") : Loop strText = Replace(strText, "§", vbCrLf & vbCrLf & vbTab) 'Done UnWrap = strText End Function