outlook 2007 - search all folders for mail with subject

  • Thread starter Thread starter soler
  • Start date Start date
S

soler

Need to create a script for outlook 2007 where I can search all folders for
e-mail to a group or mail alias.

Any help greatly appreciated.
 
I wrote the VBA code below as an answer to another post. You could easy
adapt it for your own purposes:-

Public Sub ScanAllFolders()
Dim objFolder As MAPIFolder
Dim lngItems As Long
Dim lngCounter As Long
Set objFolder =
Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent
Call ScanFolder(objFolder)
Set objFolder = Nothing
End Sub
Private Sub ScanFolder(objMAPIFolder As MAPIFolder)
Dim lngItems As Long
Dim lngCounter As Long
Dim objMailItem As MailItem
Dim objFolder As MAPIFolder
For Each objFolder In objMAPIFolder.Folders
Call ScanFolder(objFolder)
Next
For lngCounter = 1 To objMAPIFolder.Items.Count
If TypeName(objMAPIFolder.Items(lngCounter)) = "MailItem" Then
Set objMailItem = objMAPIFolder.Items(lngCounter)
If Instr(objMailItem.To,"(e-mail address removed)")>0 Then
Debug.Print objMailItem.SentOn, objMailItem.Subject
End If
Set objMailItem = Nothing
End If
Next
End Sub
 
Back
Top