MrHelpcel
New Member
- Joined
- Jan 21, 2022
- Messages
- 32
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
- 2003 or older
- Platform
- Windows
Hello all!
I have a question regarding extraction of HTML tables of a specific format (not your standard rows and columns table) from outlook, and to put the corresponding information in row format on an excel file.
Previously, with the help of Domenic on this forum (which I CANNOT THANK ENOUGH for all the help he provided me with) I managed to extract all the conventional HTML tables from a specific outlook subfolder. This resulted in a huge file with all the data recorded in rows per table (which was exactly what I wanted). Please see the link for reference: Outlook/VBA - Extracting tables from all emails in a specific folder
However, there are some HTML tables (sort of) that still haven't been successfully extracted. The reason I add the "sort of" part, is due to the nature of these tables. In the source, they are categorized as tables, but they are not your standard row and column tables. I will provide a screenshot of it (sorry for all the censoring, I don't want to get in trouble with the company!):
Is there a way to obtain information from this table to into excel?
Would it be possible to write some VBA code to extract the information from the little "Enter text here" fields? I already have some code that helped me in retrieving the data from the previous tables (the standard row and column tables), perhaps it could be modified to grab this data instead?
I would be very thankful for any help that you guys can provide!
I have a question regarding extraction of HTML tables of a specific format (not your standard rows and columns table) from outlook, and to put the corresponding information in row format on an excel file.
Previously, with the help of Domenic on this forum (which I CANNOT THANK ENOUGH for all the help he provided me with) I managed to extract all the conventional HTML tables from a specific outlook subfolder. This resulted in a huge file with all the data recorded in rows per table (which was exactly what I wanted). Please see the link for reference: Outlook/VBA - Extracting tables from all emails in a specific folder
However, there are some HTML tables (sort of) that still haven't been successfully extracted. The reason I add the "sort of" part, is due to the nature of these tables. In the source, they are categorized as tables, but they are not your standard row and column tables. I will provide a screenshot of it (sorry for all the censoring, I don't want to get in trouble with the company!):
Is there a way to obtain information from this table to into excel?
Would it be possible to write some VBA code to extract the information from the little "Enter text here" fields? I already have some code that helped me in retrieving the data from the previous tables (the standard row and column tables), perhaps it could be modified to grab this data instead?
VBA Code:
Option Explicit
Sub demo()
Dim oApp As Outlook.Application
Dim oMapi As Outlook.MAPIFolder
Dim oMail As Outlook.MailItem
Dim oItem As Variant
Dim oHTML As MSHTML.HTMLDocument
Dim oTable As MSHTML.HTMLTable
Dim oTables As MSHTML.IHTMLElementCollection
Dim nextRow As Long
Dim x As Long
Dim y As Long
On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
If oApp Is Nothing Then
Set oApp = CreateObject("Outlook.Application")
If oApp Is Nothing Then
MsgBox "Unable to start Outlook!", vbExclamation, "Outlook"
Exit Sub
End If
End If
On Error GoTo 0
Set oMapi = oApp.GetNamespace("MAPI").Folders("folder1").Folders("folder2").Folders("folder3").Folders("folder4")
nextRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
For Each oItem In oMapi.Items
If TypeName(oItem) = "MailItem" Then
Set oMail = oItem
Set oHTML = New MSHTML.HTMLDocument
With oHTML
.Body.innerHTML = oMail.HTMLBody
Set oTables = .getElementsByTagName("table")
End With
For Each oTable In oTables
For x = 0 To oTable.Rows.Length - 1
For y = 0 To oTable.Rows(x).Cells.Length - 1
If y = 1 Then
Cells(nextRow, "A").Value = oMail.ReceivedTime
Cells(nextRow, "B").Value = oMail.Subject
Cells(nextRow, "C").Offset(y - 1, x).Value = oTable.Rows(x).Cells(y).innerText
End If
Next y
Next x
nextRow = nextRow + 1
Next oTable
Set oHTML = Nothing
Set oMail = Nothing
End If
Next oItem
Set oApp = Nothing
Set oMapi = Nothing
Set oMail = Nothing
Set oHTML = Nothing
Set oTable = Nothing
Set oTables = Nothing
End Sub
I would be very thankful for any help that you guys can provide!