如何使用VBA修改单词表

时间:2011-05-09 15:04:58

标签: vba ms-word word-2003

我有正在创建的表,我希望能够通过VBA中的代码修改它们。

我需要对表进行合并并调整一些单元格的大小,并将文本添加到某些单元格中。

2 个答案:

答案 0 :(得分:5)

要附加Lance所说的内容,这里是合并单元格并在这些合并单元格的值中设置文本的示例:

Dim myCells As Range
With ActiveDocument
    Set myCells = .Range(Start:=.Tables(1).Cell(1, 1).Range.Start, End:=.Tables(1).Cell(1, 3).Range.End)
    myCells.Select
End With

Selection.Cells.Merge


ActiveDocument.Tables(1).Cell(Row:=1, Column:=1).Range.Text = "Value for Merged Cells"

注意:此示例中的表有三列和两行

答案 1 :(得分:3)

您需要访问Table对象,例如

ActiveDocument.Tables(1).Cell(Row:=2, Column:=2).Range.Text

<some Word.Document here>.
  Content.Tables(1).Columns.SetWidth <columnwidthhere>, wdAdjustSameWidth