At times, you may need to create charts from all tables in your Outlook email. Thus, in this article, we will introduce you a quick method to get it in bulk.
Perhaps you’ve created several tables when composing a mail. And later, in order to make the table statistics more intuitive and attractive, you would like to create charts for these tables. Usually, you can create one by one by “Insert” > “Object” > “Microsoft Graph Chart”. However, it will be blazing tedious if there are multiple tables. Hence, in the followings, we will teach you a more effective way.
Batch Create Charts from Tables in Email
- At first, press “Alt + F11” to trigger Outlook VBA editor.
- Then, add “MS Excel Object Library” and “MS Word Object Library” with the reference to “How to Add an Object Library Reference in VBA“.
- Next, open an unused module and put the following VBA code into it.
Sub CreateChartsfromAllTablesInEmail() Dim objMail As Outlook.MailItem Dim objMailDocument As Word.Document Dim objTable As Word.Table Dim lTableCount As Long Dim objExcelApp As Excel.Application Dim objWorkbook As Excel.Workbook Dim objWorksheet As Excel.Worksheet Dim i As Long Dim objChart As Object Dim objInsertedChart As Excel.ChartObject 'Get the current email Set objMail = Outlook.Application.ActiveInspector.CurrentItem Set objMailDocument = objMail.GetInspector.WordEditor If objMailDocument.Tables.Count > 0 Then Set objExcelApp = CreateObject("Excel.Application") Set objWorkbook = objExcelApp.Workbooks.Add objExcelApp.Visible = True 'Convert tables to charts through Excel For i = 1 To objMailDocument.Tables.Count Set objTable = objMailDocument.Tables(i) objTable.Range.Copy objWorkbook.Sheets(i).Paste objWorkbook.Sheets(i).Columns.AutoFit Next For Each objWorksheet In objWorkbook.Sheets If objExcelApp.WorksheetFunction.CountA(objWorksheet.UsedRange) = 0 Then objWorksheet.Delete End If Next For Each objWorksheet In objWorkbook.Sheets Set objChart = objWorkbook.Charts.Add Set objChart = objChart.Location(Where:=xlLocationAsObject, Name:=objWorksheet.Name) objChart.ChartType = xlColumnClustered objChart.SetSourceData Source:=objWorksheet.UsedRange Next 'Copy the charts from Excel to email For Each objWorksheet In objWorkbook.Sheets For Each objInsertedChart In objWorksheet.ChartObjects objInsertedChart.Copy objMailDocument.Range(0, 0).Paste Next Next 'Close Excel objWorkbook.Close False objExcelApp.Quit End If End Sub
- After that, add this macro to Quick Access Toolbar of Message window by the steps introduced in the “How to Run VBA Code in Your Outlook“.
- Finally, you can have a try.
- First off, open and compose the email with multiple tables.
- Then, click the macro button in Quick Access Toolbar.
- When macro finishes, you’ll get the charts created from the tables in the email, like the following screenshot.
Safeguard Outlook Data File
Due to the fact that Outlook is vulnerable, you have to pay much attention to the integrity of your Outlook data file. For instance, you should never download any unknown attachments or open the malicious links, preventing virus attack. Plus, it is necessary to make regular backups for your Outlook. Last but not least, it is prudent to prepare a reliable and tip-top Outlook repair utility, like DataNumen Outlook Repair. It will surely come in handy in case of serious Outlook damage.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair mdf and outlook repair software products. For more information visit www.datanumen.com