VBA | Excel<--&燃气轮机;单词“Can';不要将边框添加到第一行
我想创建一个带有一些标题的表,并向该表中添加行 创建表格:VBA | Excel<--&燃气轮机;单词“Can';不要将边框添加到第一行,excel,vba,ms-word,Excel,Vba,Ms Word,我想创建一个带有一些标题的表,并向该表中添加行 创建表格: Dim objRange As Word.Range Dim objTable As Word.Table Dim celTable As Word.Cell Set objRange = oDoc.Bookmarks("tbl").Range oDoc.Tables.Add objRange, 1, 6 Set objTable = oDoc.Bookmarks("tbl").R
Dim objRange As Word.Range
Dim objTable As Word.Table
Dim celTable As Word.Cell
Set objRange = oDoc.Bookmarks("tbl").Range
oDoc.Tables.Add objRange, 1, 6
Set objTable = oDoc.Bookmarks("tbl").Range.Tables(1)
objTable.AutoFitBehavior (wdAutoFitWindow)
With objTable
.Cell(1, 1).Range.Text = "A"
.Cell(1, 2).Range.Text = "B"
.Cell(1, 3).Range.Text = "C"
.Cell(1, 4).Range.Text = "D"
.Cell(1, 5).Range.Text = "E"
.Cell(1, 6).Range.Text = "F"
.Cell(1, 1).Range.Font.Bold = True
.Cell(1, 2).Range.Font.Bold = True
.Cell(1, 3).Range.Font.Bold = True
.Cell(1, 4).Range.Font.Bold = True
.Cell(1, 5).Range.Font.Bold = True
.Cell(1, 6).Range.Font.Bold = True
'for testing reasons only one cell.
.Cell(1, 1).Borders(wdBorderBottom).Visible = True
.Cell(1, 1).Borders(wdBorderBottom).LineStyle = wdLineStyleDouble
End With
'Adding rows to the table
For Each x In collection
Dim newRow As Word.Row
Set newRow = objTable.Rows.Add()
Set objRange = newRow.Range
newRow.Cells(1).Range.Text = "..."
newRow.Cells(2).Range.Text = "..."
newRow.Cells(3).Range.Text = "..."
newRow.Cells(4).Range.Text = "..."
newRow.Cells(5).Range.Text = "..."
newRow.Cells(6).Range.Text = "..."
Next x
我的问题是,添加行后,边框不会添加到第一行(即使我将边框添加到第一行的第一个单元格)。边框显示在表格的末尾(最后一行)。因为添加表格时表格只有一行,所以边框被解释为属于表格而不是单元格。如果在添加边框之前添加一行或多行,将获得所需的边框
With objTable
With .Rows(1).Borders(wdBorderBottom)
.Visible = True
.LineStyle = wdLineStyleDouble
End With
End With