word.document.tables.add(....) 返回的是一个table,可是无论我用什么对象来接受这个返回值都不行,请问应该用什么来接收阿?

解决方案 »

  1.   

    Public Function FormatStatInfoToWord(msgData As MSHFlexGrid, ByVal FilePath As String, Optional PassWord As String = "") As Boolean
        On Error GoTo Err_FormatStatInfoToWord
        MsgBox "系统开始排版操作!", vbInformation, "系统提示"
        FormatStatInfoToWord = False
        Set WordOBJ = New Word.Application
        Set doc = WordOBJ.Documents.Add
        WordOBJ.Visible = False
        With WordOBJ
            .ActiveDocument.PageSetup.PaperSize = wdPaperCustom
            .ActiveDocument.PageSetup.PageWidth = 841.95
            .ActiveDocument.PageSetup.PageHeight = 595.35
            .Selection.Font.Name = "宋体"
            .Selection.Font.Size = 18
            .Selection.TypeText Text:="                         长青会员消费信息"
            .Selection.TypeParagraph
            .ActiveDocument.Tables.Add Range:=.Selection.Range, NumRows:=msgData.Rows - 1, NumColumns:=msgData.Cols, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
            
            Dim i As Integer, j As Long
            For i = 0 To msgData.Rows - 1
                For j = 0 To msgData.Cols - 1
                    .Selection.Font.Size = 10
                    .Selection.TypeText Text:=msgData.TextMatrix(i, j)
                    If j = msgData.Cols - 1 And i = msgData.Rows - 1 Then
                        
                    Else
                        .Selection.MoveRight Unit:=wdCell
                    End If
                Next j
            Next i
        End With
        '保存
        doc.SaveAs FileName:=FilePath, PassWord:=PassWord
        WordOBJ.Quit SaveChanges:=wdDoNotSaveChanges
        Set doc = Nothing
        Set WordOBJ = Nothing
        FormatStatInfoToWord = True
        MsgBox "排版成功,文件已存储为" & FilePath, vbInformation, "系统提示"
        Exit Function
    Err_FormatStatInfoToWord:
        WordOBJ.Quit
        Set doc = Nothing
        Set WordOBJ = Nothing
        MsgBox Err.Description, vbInformation, "系统提示"
    End Function
      

  2.   

    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:=5以为是为当前文档添加一个4行5列的表格
      

  3.   

    大哥,根本不会接收直接添加就行了,如果非要接收不可的话,可以用
    Dim myTable as Tableset mytable=ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:=5
      

  4.   

    Dim t As TableSet t = ActiveDocument.Tables.Add(Selection.Range, 10, 3)
    t.Cell(2, 2).Range.Text = "qwe" ‘将第二行第二列的格子填入qwe.