Export Data to Word

Submitted by Dennis Wallentin.

This program transfers data from Excel to a Word document. It uses early binding, so a reference must be established in the VBE (Tools, References) to the Microsoft Word Object Library.

Sub Export_Data_Word_Table() Dim wdApp As Word.Application Dim wdDoc As Word.Document Dim wdCell As Word.Cell Dim i As Long Dim wbBook As Workbook Dim wsSheet As Worksheet Dim rnData As Range Dim vaData As Variant

Set wbBook = ThisWorkbook

Set wsSheet = wbBook.Worksheets("Sheet1")

With wsSheet

Set rnData = .Range("A1:A10") End With

'Add the values in the range to a one-dimensional variant-array. vaData = rnData.Value

'Here we instantiate the new object. Set wdApp = New Word.Application

'Here the target document resides in the same folder as the workbook. Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\Test.doc")

0 0

Post a comment