gpt4 book ai didi

html - 使用替换删除文本

转载 作者:行者123 更新时间:2023-12-01 14:59:34 24 4
gpt4 key购买 nike

我想删除每封收到的外部电子邮件开头的公司句子。

THINK SECURE. This email has come from an external source. Do not click on links or open attachments unless you recognise the sender.

它以黄色突出显示。

感谢这个社区的帮助,下面的代码可以工作,但是所有后续的不相关的电子邮件互联网内容也被删除,只留下原始超链接(不再有横幅、图片..)。我只想删除上面显示的句子。

我已经尝试了 body/htmlbody/RTFbody 的所有组合。

Sub RemoveExpressionFOLDER()

Dim outNS As Outlook.NameSpace
Dim outFldr As Outlook.Folder
Dim outMailItems As Outlook.Items
'Dim outMailItem As Outlook.MailItem
Dim outMailItem As Object
'Dim myinspector As Outlook.Inspector

Set outNS = Application.GetNamespace("MAPI")
Set outFldr = Application.ActiveExplorer.CurrentFolder

'Set myinspector = Application.ActiveInspector

Set outMailItems = outFldr.Items

K = outFldr.Items.Count

For i = K - 10 To K

If outMailItems(i).Class <> olMail Then GoTo 20

outMailItems(i).Display

'outMailItems(i).UnRead = True
outMailItems(i).Body = Replace(outMailItems(i).Body, "THINK SECURE. This email has come from an external source. Do not click on links or open attachments unless you recognise the sender.", "")
'outMailItems(i).HTMLBody = Replace(outMailItems(i).HTMLBody, "THINK SECURE. This email has come from an external source. Do not click on links or open attachments unless you recognise the sender.", "")
' outMailItems(i).BodyFormat = olFormatHTML

outMailItems(i).Save
'Set myinspector = Application.ActiveInspector
'Set outMailItems(i) = myinspector.CurrentItem

outMailItems(i).Close olSave

20 Next i
MsgBox ("cleaned ")

Set outMailItems = Nothing
Set outFldr = Nothing
Set outNS = Nothing

End Sub

最佳答案

我认为您更改 HTMLBody 而不是 Body 的想法是正确的。但是,您遇到了两个问题:

一个。您无法使用 .Save 保存并使用 .Close olSave

使用方法 .Display,Outlook 已经修改了电子邮件并删除了大部分 HTML/CSS,因为 Outlook 可能不知道所有的 HTML 标签和 CSS 选择器。您会看到这种效果,尤其是响应式电子邮件。

以下应该可以解决问题:

Sub RemoveExpressionFOLDER()
For Each mail In Application.ActiveExplorer.CurrentFolder.Items
With mail
If .Class <> olMail Then continue
.UnRead = True
.HTMLBody = Replace(.HTMLBody, "THINK SECURE. This email has come from an external source. Do not click on links or open attachments unless you recognise the sender.", "")
.Close olSave
End With
continue:
Next mail
MsgBox ("cleaned ")
End Sub

关于html - 使用替换删除文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59348152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com