Reading Email from Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Thank you much sir... Just what I needed.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top