问题
Dear people at Stackoverflow,
I would like to replace for every incoming e-mail the paragraph marks (^p i believe, at least in outlook Find & Replace) with manual line breaks (^l).
I've not been able to find a solution trough Google, but I might be searching wrong.
I am using the following code as a rule for every incoming e-mail:
(FYI this code works just fine with text)
Sub testing(MyMail As MailItem)
MyMail.HTMLBody = Replace(MyMail.HTMLBody, "example", "changedtext")
MyMail.Save
End Sub
Now I have tried to change the 2nd line to:
MyMail.HTMLBody = Replace(MyMail.HTMLBody, "^p", "^l")
And
MyMail.HTMLBody = Replace(MyMail.HTMLBody, "chr(13)", "chr(10)")
But these did not seem to work.
Unfortunately I'm not very familiar with VBA coding.
I've just been told I need to use chr() but I don't have a clue on how to do that.
Some background information:
I am using 2 rules, 1 to change every ^p with ^l and the other rule is to convert the email from HTML to plain text.
If I just convert it without first changing the ^p with ^l it will have all these extra empty lines.
Example:
I would really appreciate it!
Regards,
Kris
回答1:
There are several ways to do it, but all with the same side-effect. If user SHIFT + ENTER 2 times, they will result in 1 new line also
Solution 1: 'Replace 2 newline into 1 newline
'vbCrLf is actually Chr(13) & Chr(10)
mail.HTMLBody = Replace(mail.HTMLBody, vbCrLf & vbCrLf, vbCrLf)
Solution 2: 'Replace any extra newline into "" there will be an extra blank link at the very end
tmp = Split(mail.HTMLBody, vbCrLf)
For Each Line In tmp
If Line <> "" Then
newBody = newBody & Line & vbCrLf
End If
Next
mail.HTMLBody = newBody
来源:https://stackoverflow.com/questions/13950252/vba-outlook-replace-paragraph-mark-with-manual-line-break