0

我收到了一个包含许多 ActiveX 文本框的 Word 文档,我需要在其中粘贴信息或输入信息;不幸的是,这些文本框中的每一个都将其 Multiline 属性设置为 False。

有没有办法编写一个宏来在我的文档中的每个文本框上操作此属性(如果可以在打开文档时完成此操作,则可以添加奖励)?

我了解您可能需要单独操作每个控件?如果是这样,我的文本框都具有相似的名称,即TextBox1, TextBox2,因此可以循环遍历它们。

Sub Document_TextBoxes()
    'code to loop through each text box in document and set its multiline property to True?
End Sub
4

1 回答 1

0

With the help of this SO, you can do it to all ActiveX objects:

Sub EnableMultiline()
    On Error Resume Next
    Dim i As Long, oInShp As InlineShape, sTxt As String

    For Each oInShp In ThisDocument.InlineShapes
        i = i + 1
        Err.Clear
        With oInShp.OLEFormat.Object
            sTxt = i & vbTab & .Name
            sTxt = sTxt & " [" & .MultiLine & " -> "
            .MultiLine = True
            sTxt = sTxt & .MultiLine & "]"
            If Err.Number <> 0 Then sTxt = sTxt & " <<-- FAILED"
        End With
        Debug.Print sTxt
    Next
End Sub

You can check the output in the Immediate window to see which have been changed. Used On Error Resume Next as there may be other type of ActiveX objects. After all, your goal was just to set the MultiLine property to True for all ActiveX text boxes.

于 2013-11-12T00:34:43.450 回答