-
Exporting contents of inbox to for trend data
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:
[VBA]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[/VBA]
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
-Once my PC stopped working, so I kicked it......Then it started working again
-
Maybe check on the type of objOLMail, you can have mailtypes, tasktypes, readreceipt ... I believe it's something like this :
[VBA]objOLMail.Class = olMail[/VBA]
When it's indeed a mailitem, do your stuff else do nothing.
Just a thought.
Charlize
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules