【问题标题】:How to check specific email in current email box?如何查看当前邮箱中的特定邮件?
【发布时间】:2021-11-22 19:11:49
【问题描述】:

我正在将特定的电子邮件数据导出到 Excel。 如果用户在用户表单中输入错误的电子邮件标题然后我的 c

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    您无法通过Application.ActiveExplorer.CurrentFolder.Items(EmailTitle) 直接获取该项目。

    您可以使用ActiveExplorer.CurrentFolder.Items(i) 一次查看所有项目。

    用于演示。这是最慢的方式,但足以满足“合理”数量的项目。
    FindRestrict 更可取。

    Option Explicit
    
    Private Sub CommandButtonS_click()  'Declare outlook variables
    
    Dim currFolder As folder
    Dim oLookObject As Object
    Dim oLookMailitem As mailItem
    
    Dim EmailTitle As String
    
    Dim i As Long
    Dim foundFlag As Boolean
    
    EmailTitle = "Test"
    
    Set currFolder = ActiveExplorer.CurrentFolder
    
    ' This is the slowest way but sufficient for a folder with a "reasonable" number of items.
    ' Find or restrict is preferable.
    
    For i = 1 To currFolder.Items.Count
    
        Set oLookObject = currFolder.Items(i)
        
        If oLookObject.Class = olMail Then
        
            Set oLookMailitem = oLookObject
            
            ' Now you may check for a mailitem property
            If oLookMailitem.subject = EmailTitle Then
                Debug.Print oLookMailitem.subject
                'oLookMailitem.Display
                foundFlag = True
                Exit For    ' Stop looking when item found.
            End If
        End If
        
    Next
    
    If foundFlag = False Then
        MsgBox "This email is not in your current outlook email box Or incorrect email title." & _
          vbCr & "Please choose the correct email box Or correct the email title."
    End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 2011-05-26
      • 2020-02-11
      • 2011-03-12
      • 2013-02-23
      • 2011-12-08
      • 2014-02-20
      • 1970-01-01
      相关资源
      最近更新 更多