I'm trying read a stack of saved .msg emails in a folder on a shared drive.
I can't get into Outlook to search directly because my organisation won't allow me to because it's a department shared email.
The saved folder is my workaround. I need to pull the file path and the date that we received the email from these files and put them into Excel. I can't take the date that the file was created because otherwise that'll be the date that I saved the file.
I managed to get the file path, but as soon as I try to get the received time it breaks.
I tried setting the ReceivedTime
as an object, a string, a date.
If I Dim it as an object it whines that it's object not set, if I set the ReceivedTime
it does the same.
If I dim it as string I get error 91, if I remove the with statement it still gives me error 91.
If I delete ReceivedTime = MailItem.ReceivedTime
it moves on to the next time it's mentioned and yells at me about that part.
I checked my spelling of Received all through the code and that's not it.
Here's my code at the moment. I edited the file location for privacy. It works without the received time part, so the file location isn't the problem.
Sub FileSearchAlt()
Worksheets("Sheet1").Activate
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Integer
Dim oMsg As Outlook.MailItem
Dim MailItem As Object
Dim ReceivedTime As String
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users\THE LOCATION OF MY FILE")
With oMsg
ReceivedTime = MailItem.ReceivedTime
For Each oFile In oFolder.Files
Cells(i + 1, 1) = "C:\Users\THE LOCATION OF MY FILE" & oFile.Name
Cells(i + 1, 2) = MailItem.ReceivedTime
i = i + 1
Next oFile
End With
End Sub