Consulting

Results 1 to 2 of 2

Thread: Excel VBA to extract specific outlook emails

  1. #1

    Excel VBA to extract specific outlook emails

    Hi Guys,

    I've included some prelim VBA code that extracts certain outlook properties from Outlook across to Excel based on Sender, Time and Importance. I am looking to restrict the output to Excel so it only includes all rows/records that feature sender M and excludes all other senders- is this possible?

    I am aware of being able to use IF and restrict function but I though that it was limited to the Outlook properties?

    Thanks so much for any help
    Attached Files Attached Files

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,158
    Location
    Maybe:
    Sub extract_specifics()    Dim olapp As Outlook.Application
        Dim olmail As Outlook.MailItem
        Dim olns As Outlook.Namespace
        Dim olfolder As Outlook.Folder
        Dim sName As String
        
        Set olapp = New Outlook.Application
        Set olmail = olapp.CreateItem(olMailItem)
        Set olns = olapp.GetNamespace("MAPI")
        Set olfolder = olns.GetDefaultFolder(olFolderInbox)
        i = 1
        
        For Each olmail In olfolder.Items
            sName = olmail.SenderName
            If sName = Range("I3").Value Then
                i = i + 1
                Cells(i, 1) = sName
                Cells(i, 2) = olmail.ReceivedTime
                Cells(i, 3) = olmail.Importance
            End If
        Next olmail
    End Sub
    Range("I3") is the name of the sender to be included.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2401, Build 17231.20084

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •