【问题标题】:Find Text in an email and delete all text after this in Outlook 2010在电子邮件中查找文本并在 Outlook 2010 中删除此之后的所有文本
【发布时间】:2014-07-31 06:43:19
【问题描述】:

我正在尝试在电子邮件中查找文本并在此之后删除所有文本。 我已经设法在 Word 2010 中获得了一个有效的宏,但是我无法在 Outlook 中复制类似的东西。

总会有一个特定的文本标题“文本”,然后是一些文本,这对于每封电子邮件确实有所不同。

我一直使用的宏:这取自Find a string in a document and delete everything after it

Sub DeleteText()

Set myRange = Application.ActiveInspector.CurrentItem
myRange.Find.Execute FindText:="Text", _
    Forward:=True
If myRange.Find.Found = True Then
myRange.SetRange (myRange.End + 1), ActiveDocument.Content.End
myRange.Delete

End If

End Sub

关于如何在 Outlook 2010 中实现类似功能的任何建议?

【问题讨论】:

    标签: vba outlook outlook-2010


    【解决方案1】:

    首先打开一个邮件项目,然后尝试这个未经测试的代码。

    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
    

    【讨论】:

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