如何从电子邮件中删除短语?

问题描述 投票:0回答:1

我想从特定域以外的来源的每封电子邮件的开头删除以下短语:

“这是外部电子邮件。除非您验证发件人并且知道内容安全,否则请不要单击链接或打开附件。”

我正在尝试从每封电子邮件中删除此短语。

[我从另一个试图做类似事情的人那里在线获取了一些代码。

Sub Del()

Dim Ins As Outlook.Inspector
Dim Document As Word.Document
Dim Word As Word.Application
Dim Selection As Word.Selection

Set Ins = Application.ActiveInspector
Set Document = Ins.WordEditor
Set Word = Document.Application
Set Selection = Word.Selection

Dim search As String
search = "This is an EXTERNAL email. Do not click links or open attachments unless you validate the sender and know the content is safe."

Dim para As Paragraph
For Each para In Document.Paragraphs

    Dim txt As String
    txt = para.Range.Text

    If InStr(txt, search) Then
        para.Range.Delete
    End If

Next

End Sub

我知道

运行时错误'91'

在线9 Set Document

outlook-vba
1个回答
0
投票

在Outlook中更容易工作:

sub delete_part_of_text()

  Dim search As String
  search = "This is an EXTERNAL email. Do not click links or open attachments unless you validate the sender and know the content is safe."

  If Not TypeOf Item Is mailitem Then Exit Sub
  Item.HTMLBody = Replace(Item.HTMLBody, search, "")
end sub

当然,您必须对此进行调整-是否应该在每个收到的邮件上自动运行此邮件?是否需要在一封或某些邮件中调用此邮件?这就改变了程序的调用,但是基本原理起作用了。

最大

© www.soinside.com 2019 - 2024. All rights reserved.