Compartilhar via


Pesquise na caixa de entrada itens com assunto que contém "Office"

This topic shows two code samples that use DASL queries to search for items in the Inbox that contain "Office" in the subject line. The first code sample uses Folder.GetTable and the second uses Application.AdvancedSearch to apply the DASL query.

[!OBSERVAçãO] Each of the code samples uses the content indexer keyword ci_phrasematch in a DASL filter on the property https://schemas.microsoft.com/mapi/proptag/0x0037001E (the Subject property referenced by the MAPI ID namespace) to search for the word "office" in the subject. Ele aplica o filtro aos itens da Caixa de Entrada (usando Folder.GetTable ou Application.AdvancedSearch) e imprime a linha de assunto de cada item retornado pela pesquisa. Nota A correspondência não é confidencial para que qualquer item que contenha "Office" ou "office" no assunto seja retornado por Folder.GetTable ou Application.AdvancedSearch. Notice that each sample prints the subject of each row in the resultant Table. It chooses to use the lighter weight Table object instead of the Search.Results object for better performance. The Subject property is included in a Table returned by a search on any folder. But like any folder in Outlook, the Inbox can contain heterogenous items and is not confined to mail items. If you want to access a property that is specific to a certain item type in the Inbox, use Columns.Add to include that property and update the Table, and for each row returned in the Table, check the message type of the item before accessing the property. Este exemplo de código usa Folder.GetTable para fazer a pesquisa:

Sub RestrictTableForInbox() 
    Dim oT As Outlook.Table 
    Dim strFilter As String 
    Dim oRow As Outlook.Row 
     
    'Construct filter for Subject containing 'Office' 
    Const PropTag  As String = "https://schemas.microsoft.com/mapi/proptag/" 
    strFilter = "@SQL=" & Chr(34) & PropTag _ 
        & "0x0037001E" & Chr(34) & " ci_phrasematch 'Office'" 
     
    'Do search and obtain Table on Inbox 
    Set oT = Application.Session.GetDefaultFolder(olFolderInbox).GetTable(strFilter) 
     
    'Print Subject of each returned item 
    Do Until oT.EndOfTable 
        Set oRow = oT.GetNextRow 
        Debug.Print oRow("Subject") 
    Loop 
End Sub

Este exemplo de código usa Application.AdvancedSearch para fazer a pesquisa:

Public blnSearchComp As Boolean 
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) 
    MsgBox "The AdvancedSearchComplete Event fired" 
    blnSearchComp = True 
End Sub 
 
Sub TestSearchWithTable() 
    Dim oSearch As Search 
    Dim oTable As Table 
    Dim strQuery As String 
    Dim oRow As Row 
         
    blnSearchComp = False 
     
    'Construct filter. 0x0037001E represents Subject 
    strQuery = _ 
        "https://schemas.microsoft.com/mapi/proptag/0x0037001E" & _ 
        " ci_phrasematch 'Office'" 
     
    'Do search 
    Set oSearch = _ 
        Application.AdvancedSearch("Inbox", strQuery, False, "Test") 
    While blnSearchComp = False 
        DoEvents 
    Wend 
 
    'Obtain Table 
    Set oTable = oSearch.GetTable 
     
    'Print Subject of each returned item 
    Do Until oTable.EndOfTable 
        Set oRow = oTable.GetNextRow 
        Debug.Print oRow("Subject") 
    Loop 
End Sub

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.