How to add a Textbox dynamically using VB

Asked

Viewed 670 times

-2

How to add a Textbox dynamically, whenever the Userform (List Data Combination or Validation Box) is equal to "Outro (Especificar)", using VB ?


inserir a descrição da imagem aqui

I’m lost, I’m new to making macros and forms, using VB. ^^'

I was doing with Data Validation, List.

Sub Outro()
'
' Outro Macro
coluna = 1
linha = 1
While Cells(linha, coluna).Value <> ""
    Application.Visible = False 'torna invisível a aplicação Excel
    valorCelula = Format(Cells(linha, coluna).Value, 2)
    'If valorCelula <> Cells(linha, coluna).Value Then
    '    Cells(linha, coluna).Value = valorCelula
    'End If
    linha = linha + 1
    With Selection.Font
            .Color = -16776961
            .TintAndShade = 0
        End With
        Selection.Font.Bold = True
        Range("G3").Select
        ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
           DisplayAsIcon:=False, Left:=497.25, Top:=36, Width:=66.75, Height:= _
           10.5).Select
Wend
End Sub
  • 4

    Welcome to the Sopt Dani Guido community, consider taking a look at How To Ask?, will help a lot. So, regarding your problem, I couldn’t understand what exactly you want, try add some details, parts of the code you used and are not understanding, which programming language you want to use?

  • 1

    I have an excel spreadsheet, which I have to add a list field, in it will have an option of "Other", when chosen will open a field to be filled. VB programming, using macro and such. Ex: (Title)> Point: (Options) > A; B; C; Other(Specify).

  • Try to follow these steps!

1 answer

0

Right click on the Combobox and go to:

Comando atribuir macro...

Click New on the screen that appears:

inserir a descrição da imagem aqui

I used this code on the sub Dropdown1_Alteração

Set oTB = ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1")
Set cell = ActiveSheet.Range("C2")
With oTB
.Name = "MyTB"
.LinkedCell = "$C$2"
.Left = cell.Left
.Top = cell.Top
.Width = cell.Width
.Height = cell.Height
.Object.BackColor = RGB(204, 204, 255)
.Object.ForeColor = RGB(0, 0, 255)
.Object.Text = "Texto"
End With

Browser other questions tagged

You are not signed in. Login or sign up in order to post.