Some users would like to extract the tables in an email and save them as pictures in a Windows folder. Obviously, Outlook doesn’t have such a function. But it still can be realized by means of VBA code. This article will show the details.
If you want to extract the tables of an Outlook email and recycle them, you could export and store them as pictures on a local drive. Yet, there is not such a native function in Outlook. Therefore, if you want to achieve it, you can use the following way, which is making use of VBA code.
Export All Tables in an Email as Pictures
- For a start, launch your Outlook program.
- Then, in Outlook, access VBA editor with reference to the post – “How to Run VBA Code in Your Outlook”.
- Subsequently, you need to enable “MS Excel Object Library” as well as “Ms Word Object Library”, which you can refer to the article – “How to Add an Object Library Reference in VBA“.
- Next, put the following VBA code into an unused project or module.
Sub ExportTablesAsPictures() Dim objMail As Outlook.MailItem Dim objMailDocument As Word.Document Dim objTable As Word.Table Dim objExcelApp As Excel.Application Dim objExcelWorkbook As Excel.Workbook Dim objExcelWorksheet As Excel.Worksheet Dim i As Long 'Create a new excel workbook Set objExcelApp = CreateObject("Excel.Application") Set objExcelWorkbook = objExcelApp.Workbooks.Add objExcelApp.Visible = True objExcelWorkbook.Activate 'Get the tables in the selected email Set objMail = Outlook.Application.ActiveExplorer.Selection.Item(1) Set objMailDocument = objMail.GetInspector.WordEditor 'Copy all tables into separate worksheets For i = 1 To objMailDocument.Tables.Count Set objTable = objMailDocument.Tables(i) objTable.Range.Copy Set objExcelWorksheet = objExcelWorkbook.Sheets(i) objExcelWorksheet.Paste objExcelWorksheet.Columns.AutoFit Call ExportAsImage(objExcelWorksheet, i) Next objExcelWorkbook.Close False objExcelApp.Quit End Sub Sub ExportAsImage(ByVal objSheet As Excel.Worksheet, ByRef n As Long) Dim objRange As Excel.Range Dim objThisWorksheet As Excel.Worksheet Dim objFileSystem As Object Dim strTempFolder, strImageName, strImageFile As String Dim objOutlookApp As Outlook.Application Dim objNewMail As Outlook.MailItem 'Copy the table Set objRange = objSheet.UsedRange objRange.CopyPicture 'Export the table as JPG image strImageFile = "E:\Table " & n & ".jpg" With objSheet.ChartObjects.Add(objRange.Left, objRange.Top, objRange.Width, objRange.Height) .Activate .Chart.Paste .Chart.Export strImageFile, "JPG" End With objSheet.ChartObjects(objSheet.ChartObjects.Count).Delete End Sub
- After that, you can add this macro to Quick Access Toolbar.
- Later, you can try this macro.
- First off, select an email.
- Then, click the macro button in Quick Access Toolbar.
- When the macro finishes, go to the predefined Windows folder, in which you will see the exported tables in JPG format.
Back up Outlook Data at Regular Intervals
Although Outlook earns a lot of kudos, it is still unable to get immune from errors and damage. Therefore, in order to block valuable Outlook data from loss, you’d better back up Outlook data regularly, such that even if Outlook data gets corrupt, you still can restore it from backups. Yet, if the backups prove failure, you have no choice but to resort to a robust enough Outlook recovery utility, like DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged mdf and outlook repair software products. For more information visit www.datanumen.com