我想把在数据库中检索到的数据 用 Word 表格的形式打印出来!怎样用VB 对word文档进行操作呀!?请大侠们执教!!

解决方案 »

  1.   

    用 word 做一个模版!用标签把数据按顺序一一对应导出,然后打印啊
      

  2.   

    在vb中使用vba代码,你上面那个例子的vba代码为:
    Sub Macro1()
    '
    ' Macro1 Macro
    ' 宏在 2004-3-19 由 lsf 录制
    '
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
            3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
            wdAutoFitFixed
        Selection.MoveRight Unit:=wdCell
        Selection.Cells.Split NumRows:=2, NumColumns:=1, MergeBeforeSplit:=False
        Selection.MoveRight Unit:=wdCell
        Selection.TypeParagraph
        Selection.EscapeKey
        Selection.EscapeKey
        Selection.EscapeKey
        Selection.EscapeKey
        Selection.EscapeKey
        Selection.EscapeKey
        Selection.TypeBackspace
        Selection.TypeParagraph
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.TypeParagraph
        Selection.MoveLeft Unit:=wdCharacter, Count:=2
        Selection.TypeText Text:="哈哈哈"
        Selection.TypeParagraph
        Selection.TypeText Text:="哈哈哈"
        Selection.TypeParagraph
        Selection.TypeText Text:="哈哈哈"
        Selection.MoveRight Unit:=wdCharacter, Count:=3
        Selection.TypeText Text:="哈哈哈"
        Selection.TypeParagraph
        Selection.TypeText Text:="哈哈"
        Selection.TypeParagraph
        Selection.TypeText Text:="哈哈哈哈哈"
    End Sub你可以在word中先启动“录制新宏”功能,然后手动完成你要的操作,完成后停止录制,再把刚才录制好的宏打开进行编辑,分析一下里面的vba代码就可以清楚了。