VBOffice

Insert a Formatted Excel Table into an Email

A sample for how to paste a table from Excel and retaining its formattings.

Last modified: 2007/01/29 | Accessed: 108.041  | #41
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

By using Word as e-mail editor you get access to Word's powerful object model even for e-mails. With that it's possible to insert a formatted Excel table into an Html e-mail.

This sample assumes that the e-mail and workbook are already opened and copies the range from B2 to C6 into the e-mail - inclusive all its formattings.

Via Tools/References, please add the Word and Excel libraries to your Outlook VBA project.


tip  How to add macros to Outlook
Sub PasteFormattedTable()
  Dim Doc As Word.Document
  Dim wdRn As Word.Range
  Dim Xl As Excel.Application
  Dim Ws As Excel.Worksheet
  Dim xlRn As Excel.Range

  Set Doc = Application.ActiveInspector.WordEditor
  Set wdRn = Doc.Range

  Set Xl = GetObject(, "Excel.Application")
  Set Ws = Xl.Workbooks("Mappe1.xls").Worksheets(1)

  Set xlRn = Ws.Range("b2", "c6")
  xlRn.Copy

  wdRn.Paste
End Sub
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.
email  Send a message