I need to start from scratch. I have code as long as my arm. I "simply" want to figure out how to take the date that an email was sent and insert it into a specific column in Excel. I have already figured out how to take the HTML table in the body of the email and place it in Excel. NOW, "all" I need to do is capture the date of email and drop in Column
Public Sub Driver()
Dim Item As MailItem, x%
Dim r As Object 'As Word.Range
Dim doc As Object 'As Word.Document
Dim xlApp As Object
Dim olItems As Outlook.Items
Dim sourceWB As Workbook
Dim sourceSH As Worksheet
Dim olFolder As Outlook.Folder
Dim strFile As String
Dim olEleColl As MSHTML.IHTMLElementCollection
Dim olNameSpace As Outlook.NameSpace
Dim olHTML As MSHTML.HTMLDocument: Set olHTML = New MSHTML.HTMLDocument
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim objEmail As Outlook.MailItem
Dim intRowIndex As Integer
Dim intEmailIndex As Integer
Dim objFolder As Outlook.MAPIFolder
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
.EnableEvents = False
.EnableEvents = False
.DisplayAlerts = False
End With
Set olNameSpace = Application.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
Set olItems = olFolder.Items
'olItems.Sort ("[ReceivedTime]")
Set Item = olItems(olItems.Count)
'save Outlook email's html body (tables)
With olHTML
.Body.innerHTML = Item.HTMLBody
Set olEleColl = .getElementsByTagName("table")
End With
strFile = "C:\xls\Driver.xlsx"
Set sourceWB = Workbooks.Open(strFile, , False, , , , , , , True)
Set sourceSH = sourceWB.Worksheets("Sheet1")
sourceWB.Activate
cells.Select
Selection.Delete
For Each Item In Application.ActiveExplorer.Selection
Set doc = Item.GetInspector.WordEditor
For x = 1 To doc.tables.Count
Set r = doc.tables(x)
r.Range.Copy
sourceSH.Paste
ActiveSheet.Pictures.Delete
rows(4).Delete
rows(1).EntireRow.Delete
rows(1).EntireRow.Delete
rows(1).EntireRow.Delete
Range("D:E").Delete
sourceSH.cells(sourceSH.rows.Count, 1).End(3).Offset(1).Select
sourceSH.cells(1, 4) = "Received Time"
Next
Next
sourceWB.Save
sourceWB.Close
Set sourceWB = Nothing
xlApp.Quit
Set xlApp = Nothing
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
On Error Resume Next
With OutlookMail
.To = "me@memememe.com"
.CC = ""
.BCC = ""
.Subject = "If this works!"
.Body = "Test."
.Attachments.Add ("c:\xls\Driver.xlsx")
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub