我想在电子邮件中找到一个字符串,并删除之前的所有文本。与此相反:
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
从此堆栈溢出页面获取的示例:在Outlook 2010中查找电子邮件中的文本并删除此后的所有文本
谢谢你的帮助。
关键是这样的:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句