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
    VBAX Expert
    Mar 2008
    Kent, England
    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
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

Posting Permissions

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