Porady: Programowane wyszukiwanie w określonym folderze
W tym przykładzie kodu Find i FindNext metody wyszukiwania tekstu w polu temat wiadomości e-mail, które są w odbiorczej.Metoda ta wykorzystuje ciąg filtru do sprawdzenia litery T jako literę początkową Subject tekstu.
Zastosowanie: Informacje przedstawione w tym temacie mają zastosowanie do projektów na poziomie aplikacji obsługiwanych w programach Outlook 2013 i Outlook 2010. Aby uzyskać więcej informacji, zobacz Funkcje dostępne w aplikacjach pakietu Office i typ projektu.
Przykład
Private Sub SearchInBox()
Dim inbox As Outlook.MAPIFolder = Me.Application.ActiveExplorer().Session. _
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim items As Outlook.Items = inbox.Items
Dim mailItem As Outlook.MailItem = Nothing
Dim folderItem As Object
Dim subjectName As String = String.Empty
Dim filter As String = "[Subject] > 's' And [Subject] <'u'"
folderItem = items.Find(filter)
While (folderItem IsNot Nothing)
mailItem = TryCast(folderItem, Outlook.MailItem)
If mailItem IsNot Nothing Then
subjectName = vbCrLf & mailItem.Subject
End If
folderItem = items.FindNext()
End While
subjectName = "The following e-mail messages were found: " _
& subjectName
MsgBox(subjectName)
End Sub
private void SearchInBox()
{
Outlook.MAPIFolder inbox = this.Application.ActiveExplorer().Session.
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = inbox.Items;
Outlook.MailItem mailItem = null;
object folderItem;
string subjectName = string.Empty;
string filter = "[Subject] > 's' And [Subject] <'u'";
folderItem = items.Find(filter);
while (folderItem != null)
{
mailItem = folderItem as Outlook.MailItem;
if (mailItem != null)
{
subjectName += "\n" + mailItem.Subject;
}
folderItem = items.FindNext();
}
subjectName = " The following e-mail messages were found: " +
subjectName;
MessageBox.Show(subjectName);
}
Zobacz też
Zadania
Porady: Programowane pobieranie folderu na podstawie nazwy