Parse HTML table or extract Outlook body items to excel sheet

Jaffirahamed

New Member
Joined
Feb 21, 2024
Messages
3
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
Hi Gurus,
Just joined this forum.
Good day to you all.
I have a folder in outlook where all the email messages from the other team will fall in to that folder. i want the VBA code that capture all the messages one by one in excel sheet.
The first slide is sample email message with the fields with column order number.
The second slide, the capture results should come same as like the table to the excel sheet. I have attached sample sheets for your reference.
I hope my question is clear to understand.
Thanks in advance.
I have a below where it capture the TO, subject and received but not items in body like String and table contents, i have attached sample sheet for your reference. Let me know if you need anything else.
VBA Code:
Sub getfolderitems()
    On Error GoTo ErrHandler
    
    ' Set Outlook application object.
    Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    
    Dim objNSpace As Object     ' Create and Set a NameSpace OBJECT.
    ' The GetNameSpace() method will represent a specified Namespace.
    Set objNSpace = objOutlook.GetNamespace("MAPI")
    
    Dim myFolder As Object  ' Create a folder object.
    Set myFolder = objNSpace.GetDefaultFolder(olFolderInbox)
    
    Dim otherFolder As Object
    Set otherFolder = myFolder.Folders("Fedx Request")'Insert subfolder'
    Dim objItem As Object
    Dim iRows, iCols As Integer
    iRows = 2

    ' Loop through each item in the folder.
    For Each objItem In otherFolder.Items
        If objItem.Class = olMail Then
        
            Dim objMail As Outlook.MailItem
            Set objMail = objItem

           Cells(iRows, 1) = objMail.SenderEmailAddress
           Cells(iRows, 2) = objMail.To
            Cells(iRows, 3) = objMail.Subject
            Cells(iRows, 4) = objMail.ReceivedTime
        End If
        iRows = iRows + 1
    Next
    Set objMail = Nothing
  
    ' Release.
    Set objOutlook = Nothing
    Set objNSpace = Nothing
    Set otherFolder = Nothing
ErrHandler:
    Debug.Print Err.Description
End Sub
 

Attachments

  • New Module.JPG
    New Module.JPG
    152.7 KB · Views: 20
  • sample outlook body fileds.JPG
    sample outlook body fileds.JPG
    96.8 KB · Views: 21
  • sample excel columns.JPG
    sample excel columns.JPG
    54.8 KB · Views: 21

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You'll have to process your email body. I see you already have some code (screenshot 1). So:
VBA Code:
Cells(iRows, 4) = objMail.ReceivedTime
'Add code after this line to process the body, search for certain strings etc to pull out the info you need.
'Maybe something like:
Set HeaderHTMLTable = objMail.HTMLBody.getElementsByClassname.... etc.
 
Upvote 0
Hi, Thanks for your reply.
Can you share me the code which capture all the body fields and table contents to excel?
I am struggling lot to get the code for that. I appreciate you. thanks.
 
Upvote 0

Forum statistics

Threads
1,224,872
Messages
6,181,498
Members
453,047
Latest member
charlie_odd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top