Dim arr() as String ' create the array
Dim obj As New Word.Application
Dim doc as Word.Document
Dim i as Long
' set the array dimensions
' have some code put some values into the array
' create a new document in obj and assign it to doc
' put values of the array into a word table
' in this case, starting in first table, first column, first cell
For i = lbound(arr) to ubound(arr)
doc.Tables(1).Columns(1).Cells(i - lbound(arr) + 1).Select
obj.Selection.TypeText(arr(i))
Next i
With wrdDoc
' put values of the array into a word table
' in this case, starting in first table, first column, first cell
' go to the starting cell in the Table(4)
.Bookmarks("TABLE_START").Select
For I = LBound(DocNo) To UBound(DocNo)
' Add a row to take the array line of data
.Tables(4).Rows.Add
.Tables(4).Columns(1).Cells(I - LBound(DocNo) + 2).Select
wrdApp.Selection.TypeText (DocNo(I))
.Tables(4).Columns(2).Cells(I - LBound(DocNo) + 2).Select
wrdApp.Selection.TypeText (VerNo(I))
.Tables(4).Columns(3).Cells(I - LBound(DocNo) + 2).Select
wrdApp.Selection.TypeText (DrgTitle(I))
Next I
If Dir(dirPath & "MyNewWordDoc.doc") <> "" Then
Kill dirPath & "MyNewWordDoc.doc"
End If
.SaveAs (dirPath & "MyNewWordDoc.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
Function BookmarkInTable(bkm As Word.Bookmark) As Word.Table
Dim tbl As Word.Table
For Each tbl In bkm.Parent.Tables
If bkm.Range.InRange(tbl.Range) Then
Set BookmarkInTable = tbl
Exit For
End If
Next tbl
End Function
If Dir(dirPath & "MyNewWordDoc.doc") <> "" Then
Kill dirPath & "MyNewWordDoc.doc"
End If
Dim tbl As Word.Table
On Error Resume Next
Set tbl = BookmarkInTable(wrdDoc.Bookmarks("TABLE_START"))
On Error GoTo 0
If tbl Is Nothing Then
' bookmark is not in table
Else
' run your code for putting array into the table
' use tbl as the table object
End If
Kill dirPath & "MyNewWordDoc.doc"