首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Outlook 2010中查找电子邮件中的文本并删除之后的所有文本

在Outlook 2010中查找电子邮件中的文本并删除之后的所有文本
EN

Stack Overflow用户
提问于 2014-07-31 06:43:19
回答 1查看 1.3K关注 0票数 1

我试图在电子邮件中找到文本,并在此之后删除所有文本。我在Word 2010中成功地获得了一个可工作的宏,但是我无法在Outlook中复制类似的内容。

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

我一直在为word使用的宏:这是从Find a string in a document and delete everything after it获取的

代码语言:javascript
复制
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中实现类似的内容,有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-01 14:40:52

首先打开邮件项,然后尝试以下未经测试的代码。

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25052358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档