View Single Post
 
Old 11-20-2014, 06:44 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote