Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook -- Perform operation on every MailItem in a Folder

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
I need to perform a text-parsing operation of the body of every message in an outlook folder.

I have figured out how to access the folder's count property through the Items collection object. I can even use the GetFirst method on the Items collection to access the body of the first MailItem, but I can't quite figure out how to get the program to loop through every MailItem in the folder.

Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolders As Outlook.Folders
Dim FolderINeed As Outlook.MAPIFolder
Dim myMailItem As Outlook.MailItem
Dim strText As String

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders.Item(1).Folders

Set FolderINeed = myFolders.Item("Name of Main Folder").Folders.Item("Name Of Subfolder")
counter = NamaFolder.Items.Count
Set myMailItem = FolderINeed.Items.GetFirst

For i = 1 To counter

strText = myMailItem.Body
'Perform necessary operation

'Get the next MailItem in the FolderINeed

Next
 
Try this approach:

dim MyItem as Outlook.item
....
for each MyItem in FolderINeed.Items
if typename(MyItem)="MailItem" then
strText = myItem.Body
'Perform necessary operation
end if
next MyItem
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top