PDA

View Full Version : Excel VBA to extract specific outlook emails



Mikeyabosbht
05-21-2022, 01:32 PM
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

georgiboy
05-23-2022, 03:08 AM
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