word table

  • Thread starter Thread starter v.
  • Start date Start date
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!!
 
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
 
Back
Top