VBA Outlook - 用手动换行替换段落标记 [英] VBA Outlook - Replace Paragraph Mark With Manual Line Break
问题描述
亲爱的人在Stackoverflow,
我想用每个 来电 替换掉段落标记(^ pi相信,至少在outlook查找和替换)与手动换行符(^ l)。
我一直无法找到一个谷歌解决方案,但我可能会搜索错误。
我使用以下代码作为每条传入电子邮件的规则:
(仅供参考,此代码工作正常文本)
子测试(MyMail作为MailItem)
MyMail.HTMLBody =替换(MyMail.HTMLBody,example ,changedtext)
MyMail.Save
End Sub
现在我尝试将第二行更改为:
MyMail.HTMLBody =替换(MyMail.HTMLBody,^ p,^ l)
和
MyMail.HTMLBody =替换(MyMail.HTMLBody,chr(13),chr(10))
但是这些似乎并不奏效。
不幸的是我对VBA编码不是很熟悉。
我刚刚被告知我需要使用chr(),但我不知道如何做到这一点。
<
一些背景信息:
我使用2个规则,1用^ l更改每个^ p,另一个规则是将电子邮件从HTML转换为纯文本。
如果我只是在将^ p改为^ l的情况下进行转换,它将包含所有这些额外的空行。
示例:
有人愿意帮助我吗?
我真的很感激它!
问候,
克里斯
有几种方法可以做到,但都有相同的副作用。
如果用户SHIFT + ENTER 2次,它们也会导致1行新行
解决方案1:
'将2个换行符替换为1个换行符
'vbCrLf实际上是Chr(13)& Chr(10)
mail.HTMLBody =替换(mail.HTMLBody,vbCrLf& vbCrLf,vbCrLf)
解决方案2:
'将任何额外的换行符替换为
最后会有一个额外的空白链接
tmp =分割(mail.HTMLBody,vbCrLf)
对于tmp中的每一行
如果行<> 然后
newBody = newBody&线路& vbCrLf
End If
Next
mail.HTMLBody = newBody
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:
Is someone out there that is willing to help me with this?
I would really appreciate it!
Regards,
Kris
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
这篇关于VBA Outlook - 用手动换行替换段落标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!