outlook 2007 - search all folders for mail with subject

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.
 
A

Alan Moseley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top