将 ActiveX 文本框转换为 table 单元格

Convert ActiveX text box to table cell

是否有将 Word 文档中的每个 ActiveX 文本框转换为 table 单元格 (1 x 1) 的宏示例。文本格式可以忽略。

我有这个 example for Excel,但不知道要使用哪些 Word 对象和方法。

我想使用 ActiveX 文本框来限制文本内容的大小,这在 Word table 单元格中是无法直接实现的。此外,我不想将文本表单字段插入 Word table 单元格而不是使用文本框,因为 tables.

的后续处理

没有转换的例子,这会更优雅,我写了一个解决方法,将文本框内容复制到 1x1 table。请注意,所有内联形状随后都会被删除,而不仅仅是文本框。

Sub Copy_textbox_to_new_table()
'Loops through ActiveX text boxes and copies content
'Adds table at bookmark named "bm1", "bm2", ...
'Pastes text from text box into table
'NB all text boxes to be copied must be renamed "TB1", "TB2", ...

Dim txtbText(1 To 5)
Dim txtb As InlineShape
Dim i As Long 'counter
Dim tbl(1 To 5)
Dim tblPlace As Range

On Error Resume Next

For i = 1 To 5 '<-text box names must be modified to TB1 ... TBn and value of n is To value here
    For Each txtb In ActiveDocument.InlineShapes
        If Not txtb.OLEFormat Is Nothing And _
            txtb.OLEFormat.ClassType = "Forms.TextBox.1" And _
            txtb.OLEFormat.Object.Name = "TB" & i Then
        txtbText(i) = txtb.OLEFormat.Object.Text
        
        Set tblPlace = ActiveDocument.Range.Bookmarks("bm" & i).Range
        
        Set tbl(i) = ActiveDocument.Tables.Add(Range:=tblPlace, NumRows:=1, NumColumns:=1)
        tbl(i).Cell(1, 1).Select
        Selection.Text = txtbText(i)
               
        End If
        
    Next

Next

'Delete all inline shapes
For i = ActiveDocument.InlineShapes.Count To 1 Step -1
ActiveDocument.InlineShapes(i).Select
Selection.Delete
Next i

End Sub