insert text form field into table with vb6

L

Lee.Hollowood

I added a table to a word template with N row and 4 column. I want to
insert the text form field in the 4th colum (eg Cell(i+1, 4)). I have
tried some way to do it but I was not successful. Could someone give
me some clues how to do it? The following is the code I wrote. Thanks.

Set wdapp = New Word.Application
Set doc = wdapp.Documents.Open(FileName:="c:\test.doc")
wdapp.Visible = False
' If doc.Bookmarks.Exists("sii") Then
' Set objBookmark = doc.Bookmarks("sii")
' End If

Set mytable = doc.Tables.Add(doc.Bookmarks("bookmarks").Range,
nrRow, 4)
With mytable
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.Range.Font.Size = 10
.Range.Font.Name = "Times New Roman"
.Range.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter
' Insert titles into the first cell in the second row of the table
.Cell(1, 1).Range.InsertBefore "Test Method"
.Cell(1, 2).Range.InsertBefore "Component"
.Cell(1, 3).Range.InsertBefore "Specifications"
.Cell(1, 4).Range.InsertBefore "Actual"
' Insert data into table
For i = 1 To nrRow Step 1
.Cell(i + 1, 1).Range.InsertBefore cell1(i - 1)
.Cell(i + 1, 2).Range.InsertBefore cell2(i - 1)
.Cell(i + 1, 3).Range.InsertBefore cell3(i - 1)
.Cell(i + 1, 4).Range.InsertBefore cell4(i - 1)
Next
End With

doc.SaveAs (docfilename)
doc.Close SaveChanges:=wdSaveChanges
wdapp.Quit
 

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