Word 2016- VBA- 如何在 A Table 中的选定行下方插入行?
Word 2016- VBA- How To Insert Row Below Selected Row In A Table?
以下代码在 table 中的选定行上方插入一行。如何在 table 中的选定行下方插入一行?
我试过 Set oNewRow = Selection.InsertRowsBelow
但它生成编译错误“预期的函数或变量”。
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
每个大脚架
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
以下代码在 table 中的选定行上方插入一行。如何在 table 中的选定行下方插入一行?
我试过 Set oNewRow = Selection.InsertRowsBelow
但它生成编译错误“预期的函数或变量”。
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
每个大脚架
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