RTB_DW
14-03-2013 19:08:05
Boa tarde, pessoal.
Sou novato em VBA. Estou com dificuldades de concatenar um texto fixo (string) com uma variável numérica para fins de desabilitação de textbox quando do início do formulário. Aliás, não sei se o problema é na concatenção ou no método loop que escolhi. Explico:
O código abaixo desabilita os 22 textbox de um formulário em sua inicialização:
txtNúm_G1.Enabled = False
txtNúm_G2.Enabled = False
txtNúm_G3.Enabled = False
txtNúm_G4.Enabled = False
txtNúm_G5.Enabled = False
txtNúm_G6.Enabled = False
txtNúm_G7.Enabled = False
txtNúm_G8.Enabled = False
txtNúm_G9.Enabled = False
txtNúm_G10.Enabled = False
txtNúm_G11.Enabled = False
txtNúm_G12.Enabled = False
txtNúm_G13.Enabled = False
txtNúm_G14.Enabled = False
txtNúm_G15.Enabled = False
txtNúm_G16.Enabled = False
txtNúm_G17.Enabled = False
txtNúm_G18.Enabled = False
txtNúm_G19.Enabled = False
txtNúm_G20.Enabled = False
txtNúm_G21.Enabled = False
txtNúm_G22.Enabled = False
A diferença entre seus nomes é o último dígito (txtNúm_Gi, sendo i de 1 a 22).
Até aqui tudo certo.
Gostaria de saber se é possível usar algum método loop para transformar estas 22 linhas de código em algo mais limpo. Exemplo:
Dim a As String
Dim b
Dim i As Integer
For i = 1 To 22 Step 1
a = txtNúm_G
b = a & i
b.Enabled = False
Next i
Tentei de tal forma, entretanto dá erro.
Se alguém puder ajudar, agradeço.
Grato.
Rafael
Sou novato em VBA. Estou com dificuldades de concatenar um texto fixo (string) com uma variável numérica para fins de desabilitação de textbox quando do início do formulário. Aliás, não sei se o problema é na concatenção ou no método loop que escolhi. Explico:
O código abaixo desabilita os 22 textbox de um formulário em sua inicialização:
txtNúm_G1.Enabled = False
txtNúm_G2.Enabled = False
txtNúm_G3.Enabled = False
txtNúm_G4.Enabled = False
txtNúm_G5.Enabled = False
txtNúm_G6.Enabled = False
txtNúm_G7.Enabled = False
txtNúm_G8.Enabled = False
txtNúm_G9.Enabled = False
txtNúm_G10.Enabled = False
txtNúm_G11.Enabled = False
txtNúm_G12.Enabled = False
txtNúm_G13.Enabled = False
txtNúm_G14.Enabled = False
txtNúm_G15.Enabled = False
txtNúm_G16.Enabled = False
txtNúm_G17.Enabled = False
txtNúm_G18.Enabled = False
txtNúm_G19.Enabled = False
txtNúm_G20.Enabled = False
txtNúm_G21.Enabled = False
txtNúm_G22.Enabled = False
A diferença entre seus nomes é o último dígito (txtNúm_Gi, sendo i de 1 a 22).
Até aqui tudo certo.
Gostaria de saber se é possível usar algum método loop para transformar estas 22 linhas de código em algo mais limpo. Exemplo:
Dim a As String
Dim b
Dim i As Integer
For i = 1 To 22 Step 1
a = txtNúm_G
b = a & i
b.Enabled = False
Next i
Tentei de tal forma, entretanto dá erro.
Se alguém puder ajudar, agradeço.
Grato.
Rafael