hi, I recieve attachments via emails every day. I'd like to build some VBA that will produce a report in Excel saying, what time the email came into the inbox and who it was sent by. Possibly also another column to highlight the subject line (something to be able to differentiate each attachment).
I currently am using the following which produces a dialog box that tells me the time the email was recieved/replied. can i manipulate this to produce my excel file?
Sub CheckMailTime()
' Define variables for MS Outlook objects
Dim oAppOutl As Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oMailItem As Outlook.MailItem
' Set Outlook object (NB - Outlook must be open or code'll fail)
Set oAppOutl = GetObject("", "Outlook.Application")
' Set MAPI name space
Set oNameSpace = oAppOutl.GetNamespace("MAPI")
' Set Inbox object
Set oInbox = oNameSpace.GetDefaultFolder(olFolderInbox)
'Loop thru' inbox & check date/time recvd for each mailitem
For Each oMailItem In oInbox.Items
MsgBox oMailItem.Subject & " received on: " & oMailItem.ReceivedTime
MsgBox oMailItem.Subject & " created on: " & oMailItem.CreationTime
Next oMailItem
'Clean up objects
Set oAppOutl = Nothing
Set oNameSpace = Nothing
Set oInbox = Nothing
End Sub
Many thank Brad
I currently am using the following which produces a dialog box that tells me the time the email was recieved/replied. can i manipulate this to produce my excel file?
Sub CheckMailTime()
' Define variables for MS Outlook objects
Dim oAppOutl As Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oMailItem As Outlook.MailItem
' Set Outlook object (NB - Outlook must be open or code'll fail)
Set oAppOutl = GetObject("", "Outlook.Application")
' Set MAPI name space
Set oNameSpace = oAppOutl.GetNamespace("MAPI")
' Set Inbox object
Set oInbox = oNameSpace.GetDefaultFolder(olFolderInbox)
'Loop thru' inbox & check date/time recvd for each mailitem
For Each oMailItem In oInbox.Items
MsgBox oMailItem.Subject & " received on: " & oMailItem.ReceivedTime
MsgBox oMailItem.Subject & " created on: " & oMailItem.CreationTime
Next oMailItem
'Clean up objects
Set oAppOutl = Nothing
Set oNameSpace = Nothing
Set oInbox = Nothing
End Sub
Many thank Brad