测试脚本:
EditWord "F:\test.docx"
Function EditWord(filepath)
Set oWordApp = CreateObject("Word.Application")
oWordApp.Visible = True
Set oWordDoc = oWordApp.Documents.Open(filepath)
oWordDoc.Range.Select
Set oWordSel = oWordApp.Selection
With oWordSel
Set oNewTable = .Tables.Add(.range,5,3)
oNewTable.Range.Font.Size = 8
i = 1
oNewTable.Cell(i, 1).Range.Text = "i"
oNewTable.Cell(i, 2).Range.Text = "i * 2"
oNewTable.Cell(i, 3).Range.Text = "i * 3"
For i = 2 To 5
oNewTable.Cell(i, 1).Range.Text = i - 1
oNewTable.Cell(i, 2).Range.Text = (i - 1)*2
oNewTable.Cell(i, 3).Range.Text = (i - 1)*3
Next
oNewTable.Rows.Add
i = oNewTable.Rows.Count
oNewTable.Cell(i, 1).Range.Text = i - 1
oNewTable.Cell(i, 2).Range.Text = (i - 1)*2
oNewTable.Cell(i, 3).Range.Text = (i - 1)*3
End With
End Function
实现结果: