I have the following code for extracting tables from Outlook email. However it only looks at the latest email. I need it to be able match string in the subject of the email in order to identify which email to extract the table from. Can someone please let me know what I need to add to the code below?
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Option Explicit
Sub impOutlookTable()
Dim wkb As Workbook
Set wkb = Workbooks.Add
Sheets("Sheet1").Cells.ClearContents
' point to the desired email
Const strMail AsString="first.last@outlook.com"
Dim oApp As Outlook.Application
Dim oMapi As Outlook.MAPIFolder
Dim oMail As Outlook.MailItem
OnErrorResumeNext
Set oApp = GetObject(,"OUTLOOK.APPLICATION")
If(oApp IsNothing)ThenSet oApp = CreateObject("OUTLOOK.APPLICATION")
OnErrorGoTo0
Set oMapi = oApp.GetNamespace("MAPI").Folders(strMail).Folders("inbox")
Set oMail = oMapi.Items(oMapi.Items.Count)
' get html table from email object
Dim oHTML As MSHTML.HTMLDocument:Set oHTML =New MSHTML.HTMLDocument
Dim oElColl As MSHTML.IHTMLElementCollection
With oHTML
.Body.innerHTML = oMail.HTMLBody
Set oElColl =.getElementsByTagName("table")
EndWith
'import in Excel
Dim x AsLong, y AsLong
For x =0To oElColl(0).Rows.Length -1
For y =0To oElColl(0).Rows(x).Cells.Length -1
Range("A1").Offset(x, y).Value = oElColl(0).Rows(x).Cells(y).innerText
Next y
Next x
Set oApp =Nothing
Set oMapi =Nothing
Set oMail =Nothing
Set oHTML =Nothing
Set oElColl =Nothing
wkb.SaveAs "C:\Users\user\.spyder-py3\Outlook\tables.xlsx"
EndSub</code>
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Option Explicit
Sub impOutlookTable()
Dim wkb As Workbook
Set wkb = Workbooks.Add
Sheets("Sheet1").Cells.ClearContents
' point to the desired email
Const strMail AsString="first.last@outlook.com"
Dim oApp As Outlook.Application
Dim oMapi As Outlook.MAPIFolder
Dim oMail As Outlook.MailItem
OnErrorResumeNext
Set oApp = GetObject(,"OUTLOOK.APPLICATION")
If(oApp IsNothing)ThenSet oApp = CreateObject("OUTLOOK.APPLICATION")
OnErrorGoTo0
Set oMapi = oApp.GetNamespace("MAPI").Folders(strMail).Folders("inbox")
Set oMail = oMapi.Items(oMapi.Items.Count)
' get html table from email object
Dim oHTML As MSHTML.HTMLDocument:Set oHTML =New MSHTML.HTMLDocument
Dim oElColl As MSHTML.IHTMLElementCollection
With oHTML
.Body.innerHTML = oMail.HTMLBody
Set oElColl =.getElementsByTagName("table")
EndWith
'import in Excel
Dim x AsLong, y AsLong
For x =0To oElColl(0).Rows.Length -1
For y =0To oElColl(0).Rows(x).Cells.Length -1
Range("A1").Offset(x, y).Value = oElColl(0).Rows(x).Cells(y).innerText
Next y
Next x
Set oApp =Nothing
Set oMapi =Nothing
Set oMail =Nothing
Set oHTML =Nothing
Set oElColl =Nothing
wkb.SaveAs "C:\Users\user\.spyder-py3\Outlook\tables.xlsx"
EndSub</code>