Excel VBA can automatically export a table from Excel into a Word document, saving time when generating reports, summaries, or client deliverables. This method preserves formatting like borders, fonts, and cell alignment without manual copy-pasting. Before starting, ensure you have enabled the Microsoft Word Object Library in Excel’s VBA editor and have a table of data ready in Excel with headers and consistent rows.

What You'll Need

  • Microsoft Excel with VBA enabled (Excel 2010 or later)
  • Microsoft Word installed on the same machine
  • A data table in Excel with at least one row of headers and multiple data rows
  • Access to the VBA editor (press Alt+F11 in Excel)
  • The Microsoft Word Object Library reference enabled in VBA (Tools > References > Check "Microsoft Word xx.x Object Library")

Step-by-Step

  1. Open your Excel workbook containing the table you want to export. Ensure the table has clear headers and no merged cells across rows—merged cells can break the table structure in Word.
  2. Press Alt+F11 to open the VBA editor. In the Project Explorer, right-click your workbook name under VBAProject and select Insert > Module to create a new code module.
  3. Copy and paste the following VBA code into the new module. Replace "Sheet1" with the actual name of your worksheet and "A1:D10" with the exact range of your table (including headers):
    Sub ExportTableToWord()
        Dim wdApp As Object
        Dim wdDoc As Object
        Dim wdRange As Object
        Dim excelTable As Range
        
        Set excelTable = Sheets("Sheet1").Range("A1:D10")
        
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If wdApp Is Nothing Then
            Set wdApp = CreateObject("Word.Application")
        End If
        On Error GoTo 0
        
        wdApp.Visible = True
        Set wdDoc = wdApp.Documents.Add
        Set wdRange = wdDoc.Range
        
        excelTable.Copy
        wdRange.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
        
        wdDoc.Range(0, 0).InsertBefore "Exported Table from Excel"
        wdDoc.Range(0, 0).Font.Bold = True
        wdDoc.Range(0, 0).Font.Size = 16
        wdDoc.Range(0, 0).ParagraphFormat.Alignment = 1 ' Center
        
        wdApp.Activate
    End Sub
  4. Adjust the range in the code to match your exact data table. For example, if your table starts at B2 and ends at F25, change "A1:D10" to "B2:F25".
  5. If your table spans multiple sheets, ensure the correct sheet name is referenced in the code. Sheet names are case-sensitive and must match exactly, including spaces.
  6. Save your Excel file as a macro-enabled workbook (.xlsm) to preserve the VBA code. Go to File > Save As and select "Excel Macro-Enabled Workbook (*.xlsm)" from the file type dropdown.
  7. Return to Excel, press Alt+F8, select "ExportTableToWord", and click Run. A new Word document will open with your table pasted in.
  8. Verify that the table appears with proper borders, column widths, and text alignment. If the table is cut off, check that your Word document margins are not too narrow.

Common Mistakes

  • Not enabling the Word Object Library reference in VBA, which causes a "User-defined type not defined" error when running the code.
  • Using merged cells in the Excel table—Word cannot interpret merged cells correctly and may distort the table or throw errors.
  • Referencing a non-existent worksheet name (e.g., "Sheet1" when the real name is "Data"), causing a runtime error.
  • Running the code without Word open and forgetting to set wdApp.Visible = True, making it seem like nothing happened.
  • Copying a range that includes entire columns (e.g., A:A) instead of a specific range, which can overload memory and crash the macro.

Tips

  • Use named ranges in Excel (Formulas > Define Name) to make your VBA code more maintainable. Instead of "A1:D10", use "SalesTable" and reference it as Range("SalesTable").
  • Add error handling with On Error Resume Next and On Error GoTo 0 to prevent crashes if Word is not installed or not responding.
  • To preserve Excel formatting (colors, fonts), change WordFormatting:=False to WordFormatting:=True in the PasteExcelTable line.
  • For dynamic tables that grow or shrink, use Range("A1").CurrentRegion instead of a fixed range—it automatically selects contiguous data around cell A1.
  • After pasting, you can add a line break with wdRange.InsertParagraphAfter or insert a title with wdDoc.Content.InsertBefore.
  • Test your macro on a small table first to ensure formatting transfers correctly before applying it to large datasets.

Troubleshooting

  • "Run-time error '429': ActiveX component can't create object" — This means Word is not installed or the reference is missing. Reopen VBA, go to Tools > References, and check "Microsoft Word xx.x Object Library". If it’s grayed out, Word may not be installed.
  • Table appears without borders in Word — Use wdDoc.Tables(1).Borders.Enable = True after pasting. Add this line after the PasteExcelTable line: wdDoc.Tables(1).Borders.Enable = True
  • Word opens but no table appears — Check that the Excel range you copied contains actual data. If the range is empty, nothing will paste. Add a line like MsgBox excelTable.Count to verify the range size before copying.
  • Text wraps awkwardly or columns are too narrow — In Word, manually adjust column widths after pasting, or add code to auto-fit: wdDoc.Tables(1).AutoFitBehavior (2) 'wdAutoFitWindow
  • Macro runs but Word crashes — Close all other Word documents before running. Large tables (>500 rows) may cause memory issues; consider exporting in chunks or using a different method like exporting to PDF first.

Frequently Asked Questions

Can I export multiple tables to one Word document?

Yes. After pasting the first table, use wdRange.InsertParagraphAfter to add space, then copy and paste the next range. Repeat for each table.

Does this work with Excel tables created using Insert > Table?

Yes. The VBA code works with any contiguous range, whether it’s a formal Excel Table object or just a selected range. The key is using the correct cell reference.

Why does my table look different in Word than in Excel?

Word applies its own default styles. To preserve exact formatting, use WordFormatting:=True in the PasteExcelTable method. Colors and fonts may still vary slightly due to rendering differences.

Can I automate this to run every time I open the Excel file?

Yes, by placing the code in the Workbook_Open event. In the VBA editor, double-click "ThisWorkbook" under your project and paste the code there, calling ExportTableToWord from the Open event.

What if I don’t have Word installed?

This method requires Microsoft Word. Without it, you cannot use this VBA approach. Alternatives include exporting to PDF from Excel or using HTML tables saved as .htm files.

Will this work on a Mac?

Yes, but Word for Mac uses different object references. The VBA code may need adjustments, and the Word Object Library may be listed differently under Tools > References. Test on Mac first.