简体   繁体   中英

Outlook find Email in inbox by string (part of body)

I simply want to select all mail in my inbox that contain (in Body) a certain string. I thought Find would be a good Approach. Rather to make a for..each on all items in inbox...
However my command does (see below) not work. It brings "invalid condition"

Set Msg = Inbox.Items.Find("abc")

2 Questions:
1. How to fill in the desired condition?
2. What is result of that find? A single email or a collection I need to put in a variant or so

The Find method locates and returns a Microsoft Outlook item object that satisfies the given Filter. See Filtering Items Using Query Keywords for more information about possible query strings. After the Find method runs, the FindNext method finds and returns the next Outlook item in the specified collection. For example:

 Sub DemoFindNext() 
  Dim myNameSpace As Outlook.NameSpace 
  Dim tdystart As Date 
  Dim tdyend As Date 
  Dim myAppointments As Outlook.Items 
  Dim currentAppointment As Outlook.AppointmentItem 

  Set myNameSpace = Application.GetNamespace("MAPI") 
  tdystart = VBA.Format(Now, "Short Date") 
  tdyend = VBA.Format(Now + 1, "Short Date") 
  Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items 
  Set currentAppointment = myAppointments.Find("[Start] >= """ & tdystart &    """ and [Start] <= """ & tdyend & """") 
  While TypeName(currentAppointment) <> "Nothing" 
   MsgBox currentAppointment.Subject 
   Set currentAppointment = myAppointments.FindNext 
  Wend 
 End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM