word table

V

v.

I should write a VBA code that creates a table in a Word
sheet. This table has to contain values coming from an
Excel sheet.....help me please!!
 
D

Dick Kusleika

v

Here's an example. Set a reference (VBE - Tools - References) to the
Microsoft Word x.x Object Library.

Sub maketable()

Dim wd As Word.Application
Dim wdDoc As Word.Document
Dim i As Long
Dim j As Long

Set wd = New Word.Application
Set wdDoc = wd.Documents.Add

wd.Visible = True

wdDoc.Tables.Add wd.Selection.Range, _
Selection.Rows.Count, Selection.Columns.Count

With wdDoc.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
.Cell(i, j).Range.Text = _
Selection.Cells(i, j).Value
Next j
Next i
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top