Hi there.
I've used Power Query to export a series of emails from MS Outlook.
The result includes a column of the email body. I used a simple find/replace operation (searching for "<*>") to strip out HTML tags. After doing so, I'm left with a series of line returns, one after the other, throughout the email body.
I've been trying to write some VBA code to find instances of multiple line breaks, one after the other, and replace them with a single line break. I imagine the easiest way to accomplish this is to do a series of fine/replace options, starting with a large number of line returns, and incrementing down all the way to two. Yet nothing I'm trying has worked.
I include an example of some pretty rudimentary code, which starts with four line returns and increments down to two. Probably not what's needed, but at least this demonstrates my thinking around this.
Note that my goal is NOT to eliminate all line returns; I still want to preserve a single return where multiple appear for the sake of readability.
Thanks!
I've used Power Query to export a series of emails from MS Outlook.
The result includes a column of the email body. I used a simple find/replace operation (searching for "<*>") to strip out HTML tags. After doing so, I'm left with a series of line returns, one after the other, throughout the email body.
I've been trying to write some VBA code to find instances of multiple line breaks, one after the other, and replace them with a single line break. I imagine the easiest way to accomplish this is to do a series of fine/replace options, starting with a large number of line returns, and incrementing down all the way to two. Yet nothing I'm trying has worked.
I include an example of some pretty rudimentary code, which starts with four line returns and increments down to two. Probably not what's needed, but at least this demonstrates my thinking around this.
Note that my goal is NOT to eliminate all line returns; I still want to preserve a single return where multiple appear for the sake of readability.
Thanks!
Sub ReplaceMultipleLineReturns()
Dim MyRange As Range
For Each MyRange In ActiveSheet.UsedRange
Selection.Replace What:=Chr(10) & Chr(10) & Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Next
For Each MyRange In ActiveSheet.UsedRange
Selection.Replace What:=Chr(10) & Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Next
For Each MyRange In ActiveSheet.UsedRange
Selection.Replace What:=Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Next
End Sub