PDA

View Full Version : Exporting contents of inbox to for trend data



OTWarrior
02-10-2009, 04:29 AM
If have taken some code from another thread on this forum and modifed it to save the data, subject and sender of my inbox to a text file:
Sub EmailExporter()

Dim objOLApp As Object
Dim objMAPI As Object
Dim objOLFolder As Object
Dim objOLMail As Object
Dim LogFileName As String
Dim iFile

LogFileName = "Z:\emailLog.txt"


iFile = FreeFile


Const olFolderInbox = 6

Set objOLApp = GetObject(, "Outlook.Application")
Set objMAPI = objOLApp.GetNamespace("MAPI")

Set objOLFolder = objMAPI.GetDefaultFolder(olFolderInbox)

For Each objOLMail In objOLFolder.Items
If objOLMail.ReceivedTime < #2/1/2009# Then
Open (LogFileName) For Append As #iFile
Print #iFile, (objOLMail.ReceivedTime & "| " & Format(objOLMail.ReceivedTime, "dddd") & "| " & Format(objOLMail.ReceivedTime, "ww") & "| " & Format(objOLMail.ReceivedTime, "mmmm") & "| " & Format(objOLMail.ReceivedTime, "yyyy") & "| " & objOLMail.Subject & "| " & objOLMail.SenderName)
Close #iFile
End If
Next

Set objOLFolder = Nothing
Set objMAPI = Nothing
Set objOLApp = Nothing

End Sub

The problem I have is it doesn't do the whole lot, it fails at around the 600's email.

I am wanting to do this to import the text file into excel, that way I can make a pivot chart, and work out which days of the week are the busiest at certain times of the year.

The exact error message I get is:
Method 'RecievedTime' of object 'mailitem' failed

Charlize
02-10-2009, 05:05 AM
Maybe check on the type of objOLMail, you can have mailtypes, tasktypes, readreceipt ... I believe it's something like this :
objOLMail.Class = olMail
When it's indeed a mailitem, do your stuff else do nothing.

Just a thought.

Charlize