• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Copy data from Outlook email tables to Excel

Slipstick Systems

› Developer › Code Samples › Copy data from Outlook email tables to Excel

Last reviewed on February 8, 2018     4 Comments

What I'm looking for is to grab the table data and dump it in the same work book and sheet as new emails come in.

Using the macros on this page, when table data is received in an email, the table can be copied to an Excel worksheet.

This sample email has two tables (and a short message), we're copying the contents of the last table into Excel.
tables in an email

These are the results. The table values from additional emails would be added to after the last used row.
Send tables in an email

Note: if there are blank cells in the table, the contents of the row may paste into the wrong cell.

While the examples on this page copy the data in the second table only, you can get the data from all tables by using For x = 1 To doc.Tables.Count (and the matching Next) in place of x = doc.Tables.Count.

This version of the macro runs on the selected message(s). It saves the contents of the last table to a workbook stored in the user's Documents folder.

Sub SaveEmailTablestoExcel()
Dim Item As MailItem, x%
Dim r As Object  'As Word.Range
Dim doc As Object 'As Word.Document
Dim iRow As Long 'row index
Dim xlApp As Object, xlWB As Object
Dim xlSheet As Object
Dim strPath As String
Dim bXStarted As Boolean

Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
'the path of the workbook
 strPath = enviro & "\Documents\Book1.xlsx"
     On Error Resume Next
     Set xlApp = GetObject(, "Excel.Application")
     If Err <> 0 Then
         Application.StatusBar = "Please wait while Excel source is opened ... "
         Set xlApp = CreateObject("Excel.Application")
         bXStarted = True
     End If
     On Error GoTo 0
     'Open the workbook to input the data
     Set xlWB = xlApp.Workbooks.Open(strPath)
' Get sheet by name
     Set xlSheet = xlWB.Sheets("Sheet1")
' Get sheet by index #
     ' Set xlSheet = xlWB.Sheets(1)

xlApp.Visible = True

For Each Item In Application.ActiveExplorer.Selection
Set doc = Item.GetInspector.WordEditor
' to get all tables
 '   For x = 1 To doc.Tables.Count
' Get last table
     x = doc.Tables.Count
     Set r = doc.Tables(x)
'rows 2 - end
     For iRow = 2 To r.Rows.Count
         r.Rows(iRow).Range.Copy
'to get entire table
     ' r.Range.Copy

       xlSheet.Paste
       xlSheet.Cells(xlSheet.Rows.Count, 1).End(3).Offset(1).Select
    Next
Next
xlWB.Save

' close workbook
xlWB.Close 1
If bXStarted Then
    xlApp.Quit
End If

End Sub

 

Run a Script Rule

This is a run a script rule. It copies last table in the message to a new Excel workbook.

Outlook 2013 and 2016's Run a script rule is missing from all builds released after June 2017. To restore the run a script option, you need to set a registry key. See "Run-a-Script Rules Missing in Outlook" for more information.

Sub CopyTabletoExcel(Item As Outlook.MailItem)
Dim r As Object  'As Word.Range
Dim doc As Object 'As Word.Document
Dim iRow As Long 'row index
Dim xlApp As Object, xlWB As Object
Dim xlSheet As Object
Dim strPath As String
Dim bXStarted As Boolean

Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))

'the path of the workbook
 strPath = enviro & "\Documents\Book1.xlsx"
     On Error Resume Next
     Set xlApp = GetObject(, "Excel.Application")
     If Err <> 0 Then
         Application.StatusBar = "Please wait while Excel source is opened ... "
         Set xlApp = CreateObject("Excel.Application")
         bXStarted = True
     End If
     On Error GoTo 0
     'Open the workbook to input the data
     Set xlWB = xlApp.Workbooks.Open(strPath)
'get sheet by name
Set xlSheet = xlWB.Sheets("Sheet1")

xlApp.Visible = True

Set doc = Item.GetInspector.WordEditor
' to get all tables
 '   For x = 1 To doc.Tables.Count
' Get last table
     x = doc.Tables.Count
     Set r = doc.Tables(x)
'rows 2 - end
     For iRow = 2 To r.Rows.Count
         r.Rows(iRow).Range.Copy
'to get entire table
     ' r.Range.Copy

       xlSheet.Paste
       xlSheet.Cells(xlSheet.Rows.Count, 1).End(3).Offset(1).Select
    Next

xlWB.Save

' close workbook
xlWB.Close 1
If bXStarted Then
    xlApp.Quit
End If

End Sub

How to use the macros on this page

First: You need to have macro security set to low during testing. The macros will not work otherwise.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Some macros need to be in ThisOutlookSession, others go into a module or can be placed in either ThisOutlookSession or a module. The instructions are below.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Copy data from Outlook email tables to Excel was last modified: February 8th, 2018 by Diane Poremsky

Related Posts:

  • Send Email to Addresses in an Excel Workbook
  • Log Messages and Attachment Names
  • Use a Macro to Copy Data in an Email to Excel
  • Macro to Export Outlook Fields to Excel

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
4 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Phillip
March 5, 2020 12:17 am

This solution doesn't even come close to what is requested for help. Why does this type of time wasting stuff get propagated around. This code does not change the format of the table into column heading then data.

0
0
Reply
Carlos
June 27, 2018 3:22 pm

Having trouble getting this to copy and paste anything besides the code in outlook itself. Can't get it to work on multiple emails either. Current output is: Sub SaveEmailTablestoExcel() Dim Item As MailItem, x% Dim r As Object 'As Word.Range Dim doc As Object 'As Word.Document Dim iRow As Long 'row index Dim xlApp As Object, xlWB As Object Dim xlSheet As Object Dim strPath As String Dim bXStarted As Boolean Dim enviro As String enviro = CStr(Environ("USERPROFILE")) 'the path of the workbook strPath = enviro & "\Documents\Book1.xlsx" On Error Resume Next Set xlApp = GetObject(, "Excel.Application") If Err 0 Then Application.StatusBar = "Please wait while Excel source is opened ... " Set xlApp = CreateObject("Excel.Application") bXStarted = True End If On Error GoTo 0 'Open the workbook to input the data Set xlWB = xlApp.Workbooks.Open(strPath) ' Get sheet by name Set xlSheet = xlWB.Sheets("Sheet1") ' Get sheet by index # ' Set xlSheet = xlWB.Sheets(1) xlApp.Visible = True For Each Item In Application.ActiveExplorer.Selection Set doc = Item.GetInspector.WordEditor ' to get all tables For x = 1 To doc.Tables.Count '' Get last table ' x = doc.Tables.Count Set r = doc.Tables(x) ''rows 2 - end ' For iRow = 2… Read more »

0
0
Reply
Mark
November 7, 2017 9:02 am

Do you have any advice on how to handle the inspector when it does not fully populate? This is an all to common occurance unfortunately, when the paste only contains a partial copy of the complete set of rows, stopping at different points in the table depending on when it was ran.

0
0
Reply
Diane Poremsky
Author
Reply to  Mark
November 7, 2017 1:39 pm

Do you have multiple tables? I was troubleshooting it a couple of weeks ago and discovered it is not properly identifying the tables (at least not what i see as tables) - i added debug.print for the table and row counts, which were not correct compared to what i saw onscreen. Copying the entire range of each table got parts of the body not in the table - best guess is the message was formated with nested tables, which messed the macro up. I haven't had a lot of time to investigate it more. Sorry.

0
-2
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 36

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • This operation has been cancelled due to restrictions
  • Adjusting Outlook's Zoom Setting in Email
  • How to Hide or Delete Outlook's Default Folders
  • Disable "Always ask before opening" Dialog
  • Removing Suggested Accounts in New Outlook
  • Remove a password from an Outlook *.pst File
  • Syncing Outlook with an Android smartphone
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment