Question

I'm trying to write a sub that will get two parameters - a textbox in a form and a text. My intention is that the function will append the text into any textbox.

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

[code that appends the text parameter to the textbox]

End Sub

Please note that I'm not trying to append text to a specific textbox, but to create a function that can receive any textbox in the form and append it with any text.

Thanks for your help.

Was it helpful?

Solution

I've found the answer and it's much simpler than I though it is:

Private Sub AAA(A)

A.Value = "Desired text"

End Sub

Or if you want to append:

Private Sub AAA(A)

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

End Sub

OTHER TIPS

Hi Zephram have you managed to find the solution for this? I have one but is a bit heavy because it uses loops. If you have one better let me know.

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

can be accomplished by:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top