【问题标题】:Find Text in an email and delete all text before this in Outlook 2013在电子邮件中查找文本并在 Outlook 2013 中删除此之前的所有文本
【发布时间】:2016-07-27 20:45:30
【问题描述】:

我想在一封电子邮件中找到一个字符串,并删除它之前的所有文本。恰恰相反:

    Option Explicit

Sub DeleteAfterText()

' Deletes all text after endStr.

Dim currMail As mailitem
Dim msgStr As String

Dim endStr As String
Dim endStrStart As Long
Dim endStrLen As Long

Set currMail = ActiveInspector.CurrentItem
endStr = "Text"
endStrLen = Len(endStr)

msgStr = currMail.HTMLBody
endStrStart = InStr(msgStr, endStr)

If endStrStart > 0 Then
    currMail.HTMLBody = Left(msgStr, endStrStart + endStrLen)
End If

End Sub

来自此堆栈溢出页面的示例:Find Text in an email and delete all text after this in Outlook 2010

感谢您的帮助。

【问题讨论】:

    标签: vba outlook outlook-2010 outlook-2013


    【解决方案1】:

    关键线是这样的:

    currMail.body = Right(msgStr, Len(msgStr) - (endStrStart - 1))
    

    在原始代码中添加更多内容:

    Option Explicit
    
    Sub DeleteBeforeText_not_olFormatHTML()
    
    Dim currMail As mailItem
    Dim msgStr As String
    
    Dim endStr As String
    Dim endStrStart As Long
    Dim endStrLen As Long
    
    Set currMail = ActiveInspector.currentItem
    endStr = "Text"
    endStrLen = Len(endStr)
    
    If currMail.BodyFormat = olFormatHTML Then
        currMail.BodyFormat = olFormatRichText
    End If
    
    msgStr = currMail.body
    endStrStart = InStr(msgStr, endStr)
    
    If endStrStart > 0 Then
        currMail.body = Right(msgStr, Len(msgStr) - (endStrStart - 1))
    End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多