VB 6.0 - Creating and accessing a word table via VB6

Asked By Peter Lupton on 02-Feb-07 11:16 AM
I want to create a word document that contains a table and then puts extracted info into various cells within the table. I can create the word document and list the info I want but I can't create the table and put the info into cells.

using DocumentObject.Tables.Add collection - sundar k replied to Peter Lupton on 02-Feb-07 11:36 AM

try this code!

Function MakeWordTable(stDocument As String, stNewDocument As String)
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Dim objTable As Word.Table
Dim objRange As Word.Range
Dim x As Integer, y As Integer

Set objWord = CreateObject("Word.Application")
Set objWordDoc = objWord.Documents.Open(stDocument)
'create a range for a bookmark, you need a bookmark to create table
'dynamically
objRange = objWordDoc.Goto(wdGoToBookmark, , , "Bookmark1")

Set objTable = objWordDoc.Tables.Add(objRange, 3, 5)

For x = 1 To 3
For y = 1 To 5
objTable.Cell(x, y).Range.InsertAfter "Cell " & x & "," & y
Next y
Next x

objWordDoc.SaveAs stNewDocument
objWordDoc.Close
objWord.Quit

Set objTable = Nothing
Set objRange = Nothing
Set objWordDoc = Nothing
Set objWord = Nothing

End Function

you can also refer to below link for lot of sample codes,

Automating Word Tables for Data Insertion and Extraction

http://msdn2.microsoft.com/en-us/library/aa203688(office.11).aspx

Re ::Creating and accessing a word table via VB6.0 - Shailendrasinh Parmar replied to Peter Lupton on 18-Nov-08 07:05 AM

See the following articles for creating Table in Word document from VB 6.0 application

http://en.allexperts.com/q/Visual-Basic-1048/VIsual-Basic-6-0.htm

http://www.filebuzz.com/fileinfo/15953/HTML_Help_Generator_for_Visual_Basic_6_0.html

http://www.developerfusion.com/article/5371/visual-basic-60-exporting-a-datareport-to-microsoft-word/

Hope this helps.