Maybe something like this... you willl need to update the code with your Mailbox details
Note that you can Logon automatically with
.Logon , , False, False
Cheers
Dave
Sub Main()
Dim objSession, oFolder, oMessage
Set objSession = CreateObject("MAPI.Session
With objSession
.Logon , , False, False
Set oFolder = .InfoStores("Mailbox - Brett, David D").RootFolder
Set oFolder = oFolder.Folders("Contacts"
For Each oMessage In oFolder.Messages
MsgBox oMessage.Fields.Item(CDOPR
Next
End With
End Sub
Main Topics
Browse All Topics





by: deane_barkerPosted on 2004-09-01 at 09:59:12ID: 11955104
Are you trying to do this in a client program? I've always found it easiest to remote Outlook instead of messing with CDO. Here's a script that will iterate every item in the Contacts folder (or any folder, really) in VBScript/VBA using a function from Sue of Slipstick.com fame. Shouldn't be hard to re-purpose this to VB.
ication") ) ers(0))
(I))
Set oContactsFolder = GetFolder("Mailbox - Deane Barker\Contacts")
For Each oItem in oContacts Folder
'Do Stuff Here
Next
'This function was provided by Sue Mosher in a couple of her books and on her Web site -- I didn't write it
Function GetFolder(strFolderPath)
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders = Split(strFolderPath, "\")
Set objApp = CreateObject("Outlook.Appl
Set objNS = objApp.GetNamespace("MAPI"
Set objFolder = objNS.Folders.Item(arrFold
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders
If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function