我如何回复信件链上较早的人?
How can I reply to an earlier person on a chain of correspondence?
我的同事经常转发我的电子邮件以回复链中较早的人。通常我会向前打,然后设置我的回复。
我正在开发一个 VBA 宏,它将
- 删除我同事的留言
- 将新电子邮件地址复制到 "to" 字段中”,然后
- 插入一条预先输入的消息,例如
"Hello,
etc.
Regards"
我在另一位用户的帮助下整理了第 1 步。
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]
Sent: Tuesday, May 09, 2017 5:29 AM
在此示例中,我试图将 "firstlast@email.com" 放入收件人字段。
我会使用像这样的正则表达式来检测从以下位置获取电子邮件的行:
^[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
我的同事经常转发我的电子邮件以回复链中较早的人。通常我会向前打,然后设置我的回复。
我正在开发一个 VBA 宏,它将
- 删除我同事的留言
- 将新电子邮件地址复制到 "to" 字段中”,然后
- 插入一条预先输入的消息,例如
"Hello,
etc.
Regards"
我在另一位用户的帮助下整理了第 1 步。
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]
Sent: Tuesday, May 09, 2017 5:29 AM
在此示例中,我试图将 "firstlast@email.com" 放入收件人字段。
我会使用像这样的正则表达式来检测从以下位置获取电子邮件的行:
^[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