Macro for Email Activity

DJWH

New Member
Joined
May 9, 2008
Messages
43
I sit possible to run a macro that will record email activity from an Outlook inbox and store it in a Excel file. For example, the date received and the subject line for every email that comes into an inbox would be logged.

Many thanks in advance
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
you can likely do that from outlook VBA aswel.

but this method works for me.

Code:
Sub ReadEmails()

        'Stop Screen Updates
        Application.ScreenUpdating = False
        ' Then remember to run automatic calculations back on
        Application.Calculation = xlCalculationManual
        Application.EnableEvents = False

'set this to the folder
Set Olf = CreateObject("Outlook.Application").GetNamespace("MAPI").Folders(1).Folders("inbox")

       
i = Olf.Items.Count + 1
LR = Range("A65536").End(xlUp).Row
r = 1

Do Until r = i

subs = UCase(Olf.Items(r).Subject)
strID = Olf.Items(r).EntryID



Worksheets("Sheet1").Cells(LR, 1).Value = subs
Worksheets("Sheet1").Cells(LR, 2).Value = Date
Worksheets("Sheet1").Cells(LR, 3).Value = strID

r = r + 1
LR = LR + 1

Loop

        'Stop Screen Updates
        Application.ScreenUpdating = True
        ' Then remember to run automatic calculations back on
        Application.Calculation = xlCalculationAutomatic
        Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
Code:
Sub ReadEmails()

        'Stop Screen Updates
        Application.ScreenUpdating = False
        ' Then remember to run automatic calculations back on
        Application.Calculation = xlCalculationManual
        Application.EnableEvents = False

'set this to the folder
Set Olf = CreateObject("Outlook.Application").GetNamespace("MAPI").Folders(1).Folders("inbox")

       
i = Olf.Items.Count + 1
LR = Range("A65536").End(xlUp).Row
r = 1

Do Until r = i

subs = Olf.Items(r).Subject
daterec = Olf.Items(r).ReceivedTime
strID = Olf.Items(r).EntryID



Worksheets("Sheet1").Cells(LR, 1).Value = subs
Worksheets("Sheet1").Cells(LR, 2).Value = daterec
Worksheets("Sheet1").Cells(LR, 3).Value = strID

r = r + 1
LR = LR + 1

Loop

        'Stop Screen Updates
        Application.ScreenUpdating = True
        ' Then remember to run automatic calculations back on
        Application.Calculation = xlCalculationAutomatic
        Application.EnableEvents = True
End Sub

Slightly modified to include received date
 
Upvote 0
Thanks. I really appreciate your response. However it doesn't seem to work and I think it's to do with this line:

Set Olf = CreateObject("Outlook.Application").GetNamespace("MAPI").Folders(1).Folders("inbox")

Could you help explain this for me?

Thanks again
 
Upvote 0
Your outlook folder may have a different name or location.

Folders(1) should equal personal folders and (inbox) the inbox underneath personal folders.
 
Upvote 0
Thanks. I still get an error in that line. It says:

Run-time Error '-2147221233 (8004010f)':

The operation failed. An object could not be found.

Is it to do with "GetNamespace("MAPI")"?
 
Upvote 0
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

could be that you need to set a reference in the VBA project to the Microsoft Outlook 8.0 Object Library (in vba go to tools / References)
 
Upvote 0
That works! Thanks for all your help- I really appreciate it. Just a couple of points:

- How do I return who it's from?
- Also the third column seems to be some sort of long string- what is this?

Finally, how do I change it so that it's not my default mailbox but another one called say "Folder 2"?

Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,328
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top