Outlook VBA多个电子邮件选择

时间:2014-06-27 22:22:40

标签: vba outlook

我试图从我的选择中获取信息,但我没有运气。这是我的单一项目的代码,但无法将其与我选择的项目联系起来:

    Function GetCurrentItem() As Object
   Dim objApp As Outlook.Application

    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.currentItem
    End Select

    Set objApp = Nothing


    End Function

如何将其转换为使用精选电子邮件?

下半场Dimitry:

Sub Process_Email(oMail As MailItem)
    Dim MailSubject$
    MailSubject = LCase(Trim(oMail.Subject))

    If MailSubject = "Subject 1" Then
        Call Extract_And_Export_1(oMail.Body)

    ElseIf MailSubject = "Subject 2" Then
        Call Extract_And_Export_2(oMail.Body)


    ElseIf InStr(1, oMail.Body, "Body Field One", vbTextCompare) > 0 Then

            Call Extract_And_Export_5(oMail.Body)
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

声明您的函数返回单个项目。你怎么能从中退回多件物品?

对于Explorer,循环选择集合中的所有项目:

 Select Case TypeName(objApp.ActiveWindow)
    Case "Explorer"
        for each item in  objApp.ActiveExplorer.Selection
          MsgBox item.Subject
        next