Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access or Excel VBA loop through Outlook emails

Hi
What Access or Excel VBA code would I use to loop through my Outlook inbox and find a certain subject in new emails, then save attachments to a specific folder?
ASKER CERTIFIED SOLUTION
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Bernstein
Sub ReadOutlookFolder
   
 
     Dim olkApp As Outlook.Application, olkNS As Outlook.NameSpace, olkFolder As Outlook.MAPIFolder, olkMessage As Outlook.MailItem, strSubject As String, strBody As String
   
StartReadinbox:
   
     COunt = 0
     Set objApp = CreateObject("Outlook.Application")
     Set objNS = objApp.GetNamespace("MAPI")

     rem Inbox                                                                    incoming email address
     Set inbox = objApp.GetNamespace("Mapi").Folders("wekeelanotes@campwekeela.com").Folders("InBox")
     
      For Each objMessage In inbox.Items
         If objMessage.UnRead = True Then
            strSubject = objMessage.Subject         'subject
            strBody = objMessage.Body                 'body of message
            strsender = objMessage.SenderEmailAddress   'sender
   
            GoSub  'Process Email Data
           
            objMessage.Delete          
            COunt = COunt + 1          
         End If      
     Next  
     Exit Sub
   end sub