3

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

我需要对表格做的是合并和调整一些单元格的大小,并向一些单元格添加文本。

4

2 回答 2

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"

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

于 2011-05-09T18:06:42.440 回答
3

您需要访问 Table 对象,例如

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

或者

<some Word.Document here>.
  Content.Tables(1).Columns.SetWidth <columnwidthhere>, wdAdjustSameWidth    
于 2011-05-09T17:15:39.390 回答