处理来自Outlook的每封电子邮件的主题行

时间:2017-06-26 08:17:41

标签: excel-vba outlook-vba vba excel

目前我正在尝试处理从outlook收到的每封电子邮件的主题行。所有主题行都列在F栏上。我希望显示电子邮件的所有主题行(将删除重复项,并且每次会话只保留一行 - RE或FW的邮件已被删除这些)。新工作表将包含收件箱中的所有主题行(删除重复项后仅执行一次)。

代码:

For Each oItem In objSourceFolder.Items

    ThisWorkbook.Worksheets("Test 1 Mails").Range("A" & contor).Value = oItem.SentOn
    ThisWorkbook.Worksheets("Test 1 Mails").Range("B" & contor).Value = oItem.CreationTime
    ThisWorkbook.Worksheets("Test 1 Mails").Range("C" & contor).Value = oItem.ReceivedTime
    ThisWorkbook.Worksheets("Test 1 Mails").Range("D" & contor).Value = oItem.SenderName
    ThisWorkbook.Worksheets("Test 1 Mails").Range("E" & contor).Value = oItem.SenderEmailAddress
    If (Left(oItem.Subject, 4) = "FW: ") Or (Left(oItem.Subject, 4) = "Fw: ") Or (Left(oItem.Subject, 4) = "RE: ") Or (Left(oItem.Subject, 4) = "Re: ") Then
        oItem.Subject = Mid(oItem.Subject, 5)
        oItem.Save
         ThisWorkbook.Worksheets("Test 1 Mails").Range("F" & contor).Value = oItem.Subject
         ThisWorkbook.Worksheets("Outlook report").Range("B" & contor).Value = oItem.Subject
    Else
        If Left(oItem.Subject, 5) = "FWD: " Then
            oItem.Subject = Mid(oItem.Subject, 6)
            ThisWorkbook.Worksheets("Test 1 Mails").Range("B" & contor).Value = oItem.Subject
            ThisWorkbook.Worksheets("Outlook report").Range("B" & contor).Value = oItem.Subject
            oItem.Save
        End If
    End If

1 个答案:

答案 0 :(得分:0)

您不需要任何代码来提取所有唯一主题

  1. 在Outlook文件夹中,突出显示您要处理的所有电子邮件
  2. 点击ctrl-c(复制)
  3. 点击Excel工作表
  4. 点击ctrl-v(粘贴)
  5. 删除任何不需要的列
  6. 删除所有出现的“fw:”
  7. 删除所有出现的“re:”
  8. 选择主题栏
  9. 执行“删除重复项”命令(无论如何都在excel2016的“数据”选项卡中)
  10. ......完成