以下代码在表中所选行的上方插入一行。如何在表中所选行的下方插入行?
我尝试了CCD_ 1,但它生成了一个编译错误";预期函数或变量";。
Dim oTable As Table
Dim ocell As Cell
Dim oCC As ContentControl
Dim oNewRow As Row
Set oTable = ActiveDocument.Tables(1)
Set oNewRow = Selection.Rows.Add
Set ocell = oNewRow.Cells(1)
Set oCC = Selection.ContentControls.Add(wdContentControlRichText, ocell.Range)
With oCC
.DefaultTextStyle = "Style1"
.Tag = "Test1"
.Setplaceholdertext , , "test1"
If oCC.ShowingPlaceholderText Then
With ActiveDocument.Styles("Placeholder Text").Font
.Name = "Arial"
.Size = 8
.ColorIndex = wdRed
.Italic = True
End With
End If
End With
lbl_Exit:
Exit Sub
这太琐碎了!我不得不想知道你在这方面投入了多少精力:
Selection.InsertRowsBelow
如果你想复制一行——这是你的内容控制代码所建议的——请参阅以下任何一项:
https://www.msofficeforums.com/word-vba/27809-code-add-new-row-table.html#post87989
https://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38461
https://www.msofficeforums.com/word-vba/43603-multiple-dependent-dropdown-lists-table-add-new.html#post145675
每个Macropod
Dim oTable As Table
Dim ocell As Cell
Dim oCC As ContentControl
Dim oNewRow As Row
Set oTable = ActiveDocument.Tables(1)
**Selection.InsertRowsBelow
Set oNewRow = Selection.Rows(1)**
Set ocell = oNewRow.Cells(1)
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlRichText, ocell.Range)
With oCC
.DefaultTextStyle = "Style1"
.Tag = "test1"
.SetPlaceholderText , , "test1"
If oCC.ShowingPlaceholderText Then
With ActiveDocument.Styles("Placeholder Text").Font
.Name = "Arial"
.Size = 8
.ColorIndex = wdRed
.Italic = True
End With
End If
End With
lbl_Exit:
Exit Sub