Try the following (processing from end to start):
Code:
Dim olApp As Object
Dim olNS As Object
Dim olItems As Object
Dim olItem As Object
Dim bStarted As Boolean
Dim i As Long
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set olApp = CreateObject("Outlook.Application")
bStarted = True
End If
On Error GoTo 0
Set olNS = olApp.GetNamespace("MAPI")
Set olItems = olNS.GetDefaultFolder(6).Items 'Default inbox
For i = olItems.Count To 1 Step -1
Set olItem = olItems(i)
'Do stuff with olitem e.g.
MsgBox olItem.Subject
Next i
CleanUp:
If bStarted = True Then
olApp.Quit
End If
Set olApp = Nothing
Set olNS = Nothing
Set olItems = Nothing
Set olItem = Nothing
lbl_Exit:
Exit Sub