3

我正在尝试编写一个将获取两个参数的子程序-表单中的文本框和文本。我的意图是该函数会将文本附加到任何文本框中。

Sub AppendTextBox([any textbox in my form], text As String)

[code that appends the text parameter to the textbox]

End Sub

请注意,我不是试图将文本附加到特定的文本框,而是创建一个可以接收表单中的任何文本框并将其附加任何文本的函数。

谢谢你的帮助。

4

3 回答 3

5

我找到了答案,虽然它比我简单得多:

Private Sub AAA(A)

A.Value = "Desired text"

End Sub

或者,如果您想附加:

Private Sub AAA(A)

A.Value = A.Value & vbnewline & "Desired text"

End Sub
于 2013-06-11T13:46:00.973 回答
0

嗨 Zephram 你有没有找到解决方案?我有一个,但有点重,因为它使用循环。如果你有更好的告诉我。

Private Function change_TextBox2(altera As String, textbox As ctl, valor As Variant)
Dim ctl As Control
If altera = "Popula" Then
    For Each ctl In Me.Controls
        With ctl
         If (InStr(.Name, textbox)) > 0 Then
             .Value = valor
         End If
       End With
    Next ctl
ElseIf altera = "hide" Then
    For Each ctl In Me.Controls
        With ctl
         If (InStr(.Name, textbox)) > 0 Then
             .Visible = False
         End If
       End With
    Next ctl
End If
End Function
于 2017-06-13T15:54:11.693 回答
0

可以通过以下方式完成:

dim appendTxt as String:  appendTxt = "appended text"
dim ws as Worksheet:  for each ws in ActiveWorkbook.Worksheets
    dim shape as Shape:  for each shape in ws.Shapes
        if shape.Type = msoTextBox then
            'you can move this code parameterized to a separate function then as req by OP:
            with shape.TextEffect:  .Text = .Text & appendTxt
        end if
    next shape
next ws
于 2019-06-07T07:34:02.407 回答