View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] chip.gorman@gmail.com is offline
external usenet poster
 
Posts: 29
Default Reading Email from Excel

On Jul 25, 11:06 pm, Albert wrote:
Hello!
I have successfuly done, with your help, a macro that sends e-mail from
excel, via outlook (very cool stuff by the way).
I have a new task now. I want to import the text, subject and sender of an
e-mail received in outlook to a data base I keep in Excel.
Does someone know how to do this?
Best regards and thanks in advance,
Albert C


I assume you're been to Ron de Bruin's site, which is where I got most
of what's below.

This code will get email from a specified folder and move the email to
the Deleted Items once processed. Remove that section if you don't
want it, but this will check every email in the folder and create
duplicates if you're adding to a folder. You could add a check on date
or something too so that it only works on email from a specified
period.

Sub GetFromInbox()

Dim strEmployeeEmail As String
Dim strArrivalTime As String
Dim strSubject As String
Dim strBody As String

'late binding to Outlook
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim DelFldr As MAPIFolder
Dim olMail As Variant

Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)

Set Fldr = olNs.Folders("mailbox - Your MB name").Folders("email
test")
Set DelFldr = olNs.Folders("mailbox - Your MB
Name").Folders("Deleted items")

For Each olMail In Fldr.items

'get the values needed from the email
ArrivalTime = olMail.ReceivedTime
EmployeeEmail = olMail.SenderName
strBody = olMail.Body
strSubject = olMail.Subject

'----------------
'Add Code Here to place the variables where you want them
in your WB

'-------------------

'move the email to Deleted Items
olMail.Move DelFldr

Next olMail

Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing


End Sub