我的同事经常转发我的电子邮件回复链中的早期人。通常我会前进,然后设置我的回复。
我正在开发一个
的VBA宏“你好,
等
问候“
我已经在另一位用户的帮助下整理了第一步。
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 = "Dear"
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
运行此操作后,电子邮件将以如下所示的行开头:
From:First Last [mailto:firstlast@email.com]
发送时间:2017年5月9日星期二上午5:29
我试图将“firstlast@email.com”放入此示例中的to字段中。
答案 0 :(得分:1)
我使用像这样的正则表达式来检测从中获取电子邮件的行:
^[F][r][o][m][:].*[\[][m][a][i][l][t][o][:](\w+\@.*\..*)[\]].*$
你只需要调整一下部分就可以删除身体的开始。
完整代码:
Sub DeleteBeforeText_not_olFormatHTML()
Dim currMail As MailItem
Dim msgStr As String
Dim endStr As String
Dim endStrStart As Long
Dim endStrLen As Long
Dim regEx As New RegExp
Set currMail = ActiveInspector.CurrentItem
If currMail.BodyFormat = olFormatHTML Then
currMail.BodyFormat = olFormatRichText
End If
msgStr = currMail.Body
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = True
.Pattern = "^[F][r][o][m][:].*[\[][m][a][i][l][t][o][:](\w+\@.*\..*)[\]].*$"
End With
If regEx.test(msgStr) Then
endStr = CStr(regEx.Execute(msgStr)(0))
Debug.Print endStr
endStrLen = Len(endStr)
endStrStart = InStr(msgStr, endStr)
If endStrStart > 0 Then
currMail.Body = Right(msgStr, Len(msgStr) - (endStrStart - 1))
End If
Else
End If
End Sub