2017-05-09 4 views
1

私の同僚は、しばしば私の電子メールを転送して、チェーンの初期の人に返信します。典型的には、私は前方にヒットし、私の返信を設定します。私は連絡先の連絡先で、以前の人に返信する方法はありますか?

  1. は私の同僚のメッセージを削除します
  2. 「が」フィールド」に新しいメールアドレスをコピーして、
  3. VBAマクロに取り組んでいます


    のようなpretypedメッセージを挿入します

「こんにちは、
など
よろしく」

私は別のユーザーの助けを借りて、ステップ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 

これが実行された後、電子メールは、このような行で始まります:

から:姓[mailtoの:[email protected]]
は送信:5月9日(火曜日) 、2017 5:29 AM

この例では、「[email protected]」を「to」フィールドに入力しようとしています。

+0

あなたは電子メールの本文の例の画像を投稿することができますか? – 0m3r

答えて

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 
+1

ああ!私は同じ考えをしていた:-)、正規表現はそれを行う – 0m3r

関連する問題