如何在vb中显示固定的word表格,并从access数据库中把需要的数据填入表格中固定的地方,并最后实现打印? 如何在vb中显示固定的word表格,并从access数据库中把需要的数据填入表格中固定的地方,并最后实现打印?请高手帮忙啊,就是我有一个固定的word空白表格模板,通过查找操作把access数据库中所需要的数据添充到word表格中,并最后实现打印。打印后,word表格依然保持空白状态。谢谢啦 。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考:http://www.xrss.cn/Dev/VB/200741412388.Html 看我发的贴,希望对你有帮助.http://topic.csdn.net/u/20080805/10/e258a7fe-6302-435f-87e7-8da26c91e95f.html private sub Command1Click() Dim i As Integer Dim ifieldcount As Integer Dim ircordcount As Integer Dim wdapp As Word.Application Dim wddoc As Word.Document Dim atable As Word.Table Set wdapp = CreateObject("Word.Application") Set wddoc = wdapp.Documents.Add ircordcount = Adodc1.Recordset.RecordCount wdapp.Visible = True wdapp.Activate Set atable = wdapp.ActiveDocument.Tables.Add(wdapp.Selection.Range, ircordcount + 1, 8)'这里表示行数和列数。ircordcount + 1是行数,因为要有表头多以行数要比记录数多一行,列数为8,有多少字段就要多少列 atable.Cell(1, 1).Range.InsertAfter "字段1" atable.Cell(1, 2).Range.InsertAfter "字段2" atable.Cell(1, 3).Range.InsertAfter "字段3" atable.Cell(1, 4).Range.InsertAfter "字段4" atable.Cell(1, 5).Range.InsertAfter "字段5" atable.Cell(1, 6).Range.InsertAfter "字段6" atable.Cell(1, 7).Range.InsertAfter "字段7" atable.Cell(1, 8).Range.InsertAfter "字段8" If Adodc1.Recordset.RecordCount > 0 Then ircordcount = Adodc1.Recordset.RecordCount Adodc1.Recordset.MoveFirst Do While Adodc1.Recordset.AbsolutePosition <> adPosEOF atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" Adodc1.Recordset.MoveNext Loop If Adodc1.Recordset.AbsolutePosition = adPosEOF Then atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& "" End If Set wdapp = Nothing Set wddoc = Nothing Else MsgBox "没有可显示记录", , "提示" End If end sub别忘了在工程——引用里面把word勾上 关于vb解决用户属性中的全名 请教如何用Regexp实现文本替换? 有谁可以帮我做一个计算器呀,谢谢 请问如何将外部图像放到vb界面中 winsock有设置超时一类的地方么? 关于全局变量和调用的小问题 菜鸟问题,望大虾们指点 忙了些日子了,总有个问题不能很好的解决?希望各位大小鸟给点建议! 有偿寻求VB财务模块代码 怎么实现当前窗体关闭后 显示另外一个窗体 运行4秒之后 它又自动关闭 请高手指教 如何得到类似 office 菜单在ToolbarWindow32上的弹出菜单句柄? SSTab控件中,不同页面里的控件出现重叠?
http://topic.csdn.net/u/20080805/10/e258a7fe-6302-435f-87e7-8da26c91e95f.html
Dim i As Integer
Dim ifieldcount As Integer
Dim ircordcount As Integer
Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
Set wdapp = CreateObject("Word.Application")
Set wddoc = wdapp.Documents.Add
ircordcount = Adodc1.Recordset.RecordCount
wdapp.Visible = True
wdapp.Activate
Set atable = wdapp.ActiveDocument.Tables.Add(wdapp.Selection.Range, ircordcount + 1, 8)'这里表示行数和列数。ircordcount + 1是行数,因为要有表头多以行数要比记录数多一行,列数为8,有多少字段就要多少列 atable.Cell(1, 1).Range.InsertAfter "字段1"
atable.Cell(1, 2).Range.InsertAfter "字段2"
atable.Cell(1, 3).Range.InsertAfter "字段3"
atable.Cell(1, 4).Range.InsertAfter "字段4"
atable.Cell(1, 5).Range.InsertAfter "字段5"
atable.Cell(1, 6).Range.InsertAfter "字段6"
atable.Cell(1, 7).Range.InsertAfter "字段7"
atable.Cell(1, 8).Range.InsertAfter "字段8"
If Adodc1.Recordset.RecordCount > 0 Then
ircordcount = Adodc1.Recordset.RecordCount
Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.AbsolutePosition <> adPosEOF
atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
Adodc1.Recordset.MoveNext
Loop
If Adodc1.Recordset.AbsolutePosition = adPosEOF Then
atable.Cell(DataGrid1.Book + 1, 1).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 2).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 3).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 4).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 5).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 6).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 7).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
atable.Cell(DataGrid1.Book + 1, 8).Range.InsertAfter Adodc1.Recordset.Fields("字段名")& ""
End If
Set wdapp = Nothing
Set wddoc = Nothing
Else
MsgBox "没有可显示记录", , "提示"
End If
end sub别忘了在工程——引用里面把word勾上