簡體   English   中英

Word 2016-如何在表格的所有單元格中插入帶有內容控件的行-VBA?

[英]Word 2016- How To Insert Row Below With Content Controls In All Cells of A Table- VBA?

我有一個 1 行 5 列(單元格)的表格。

下面的代碼成功地在下面插入了一行 5 列但只有一個內容控件到第一個單元格中。

Dim oTable As table
Dim oCell As Cell
Dim oNewRow As Row
    Set oTable = ActiveDocument.Tables(1)
    Set oNewRow = oTable.Rows.Add
    Set oCell = oNewRow.Cells(1)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
lbl_Exit:
    Exit Sub

如何在行中的所有 5 個單元格中輸入內容控件?

根據蒂姆·威廉姆斯的建議:

Dim oTable As table
Dim oCell As Cell
Dim oNewRow As Row
    Set oTable = ActiveDocument.Tables(1)
    Set oNewRow = oTable.Rows.Add
    Set oCell = oNewRow.Cells(1)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
    Set oCell = oNewRow.Cells(2)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
    Set oCell = oNewRow.Cells(3)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
    Set oCell = oNewRow.Cells(4)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
    Set oCell = oNewRow.Cells(5)
    ActiveDocument.ContentControls.Add wdContentControlRichText, oCell.Range
lbl_Exit:
    Exit Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM