我试图在电子邮件中找到文本,并在此之后删除所有文本。我在Word 2010中成功地获得了一个可工作的宏,但是我无法在Outlook中复制类似的内容。
总是有一个特定的文本标题“文本”,然后一些文本之后,确实不同的每一封电子邮件。
我一直在为word使用的宏:这是从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中实现类似的内容,有什么建议吗?
发布于 2014-08-01 14:40:52
首先打开邮件项,然后尝试以下未经测试的代码。
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 Subhttps://stackoverflow.com/questions/25052358
复制相似问题