工程->引用->Microsoft Word 9.0 Object Library
Dim wdapp As New Word.Application
Dim wddoc As Word.Document
Dim wdtable As Word.Table
Set wddoc = wdapp.Documents.Open("e:\lyc.doc")
wdapp.Visible = True
wdapp.Activate
连接数据库 用data1, dbgrid1显示数据
Rows = Data1.Recordset.RecordCount
cols = Data1.Recordset.Fields.Count
Set wdtable = wdapp.ActiveDocument.Tables.Add(wdapp.Selection.Range, Rows, cols)
For i = 0 To cols - 1
For j = 0 To Rows - 1
dbgrid1.Row = i
dbgrid1.col = j
wdtable.Cell(i + 1, j + 1).Range.InsertAfter dbgrid1.Text
Next j
Next i
Set wdapp = Nothing
Set wddoc = Nothing