Compartilhar via


Filtrar o corpo de um item de email

The code sample in this topic shows how to use content indexing in a DASL query to search for mail items that contain a specific word in the body.

The code sample sets up a DASL filter on the property urn:schemas:httpmail:textdescription (the Body property referenced by its DAV namespace) and uses the content indexer keyword ci_phrasematch to search for the word "office" in the body. It then applies the filter to items in the current folder. Para acessar os resultados do filtro, ele usa o objeto Table e imprime a linha de assunto de cada item.

Observe que este exemplo imprime o assunto de cada linha na Tabela retornada; a propriedade Subject está incluída em uma Tabela retornada por uma pesquisa em qualquer pasta. But generally, a folder in Outlook can contain heterogenous items and is not confined to a single item type. If you want to access a property that is specific to an item type, 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.

Nota A indexação de conteúdo em uma consulta DASL fornece um desempenho melhor do que a palavra-chave semelhante . However, you can filter only on the text of the item body; if the body contains HTML tags, as in an HTML-formatted mail item, the tags will not be filtered. The match is not case-sensitive, so for example, any item containing "Office" or "office" in the body will be returned by Folder.GetTable. Você também pode retornar até os primeiros 255 caracteres do corpo de uma coluna de um objeto Table, adicionando-a (indicado por urn:schemas:httpmail:textdescription) a esse objeto. Não é possível usar uma consulta Jet para filtrar a propriedade Body.

Sub RestrictUsingBody() 
 Dim strFilter As String 
 Dim oT As Table 
 Dim oRow as Row 
 
 'Create DASL query for Body using content indexing phrase match for 'office' 
 strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:textdescription" _ 
 & Chr(34) & " ci_phrasematch 'office'" 
 'Obtain Table by applying the filter on the current folder 
 Set oT = Application.ActiveExplorer.CurrentFolder.GetTable(strFilter) 
 'Print subject line of each mail item in current folder that contains 'office' in the body 
 Do Until oT.EndOfTable 
 Set oRow = oT.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.