要用用word vba 给word文档插入指定行列的表格,需要用到Tables对象的Add方法。
以下示例代码可以在当前的word文档中插入一个3×3的表格,表格的样式套用“网格型”:
Visual Basic
Sub QQ1722187970()
Dim oDoc As Document
Set oDoc = Word.ActiveDocument
Dim oT As Table
With oDoc
Set oT = .Tables.Add(.Range(0, 0), 3, 3)
With oT
.Style = "网格型"
End With
End With
Set oT = Nothing
Set oDoc = Nothing
End Sub
本页共18段,354个字符,527 Byte(字节)