Autor Tema: Crear automáticamente controles en Visual Basic con un bucle CheckBox y TextBox  (Leído 3205 veces)

SchroederAaron

  • Sin experiencia
  • *
  • APR2.COM
  • Mensajes: 17
    • Ver Perfil
Hola a todos quería saber si existe alguna forma de reducir este código de VBA para un
CheckBox

CheckBox(PASO1_D, PASO2_D, PASO3_D, PASO4_D, PASO4_D, PASO5_D, PASO6_D, PASO7_D)

y para un TextBox

TextBox (ComD_1, ComD_2, ComD_3, ComD_4, ComD_5, ComD_6, ComD_7).

La cuestión es que aqui son 7 de cada uno, pero si llegaran a ser 100 o 1000 pues se pone complicado.

Este es parte el código:
Código: [Seleccionar]
PASO1_D.Caption = Worksheets("Plantilla MPD").Range("A8")
PASO1_D.Left = 6
PASO1_D.Top = 30
PASO1_D.Width = 300
PASO1_D.Height = 30
PASO2_D.Caption = Worksheets("Plantilla MPD").Range("A9")
PASO2_D.Left = 6
PASO2_D.Top = 60
PASO2_D.Width = 300
PASO2_D.Height = 30
PASO3_D.Caption = Worksheets("Plantilla MPD").Range("A10")
PASO3_D.Left = 6
PASO3_D.Top = 90
PASO3_D.Width = 300
PASO3_D.Height = 30
PASO4_D.Caption = Worksheets("Plantilla MPD").Range("A11")
PASO4_D.Left = 6
PASO4_D.Top = 120
PASO4_D.Width = 300
PASO4_D.Height = 30
PASO5_D.Caption = Worksheets("Plantilla MPD").Range("A12")
PASO5_D.Left = 6
PASO5_D.Top = 150
PASO5_D.Width = 300
PASO5_D.Height = 30
PASO6_D.Caption = Worksheets("Plantilla MPD").Range("A13")
PASO6_D.Left = 6
PASO6_D.Top = 180
PASO6_D.Width = 300
PASO6_D.Height = 30
PASO7_D.Caption = Worksheets("Plantilla MPD").Range("A14")
PASO7_D.Left = 6
PASO7_D.Top = 210
PASO7_D.Width = 300
PASO7_D.Height = 30


Lo que tenia pensado era algo similar a esto

Código: [Seleccionar]
For n=1 to 7
PASOn_D.Caption = Worksheets("Plantilla MPD").Range("A8").offset(n-1,0)
PASOn_D.Left = 6
PASOn_D.Top = 30*n
PASOn_D.Width = 300
PASOn_D.Height = 30
next n


Y para los TextBox

Código: [Seleccionar]
ComD_1.Left = 6
ComD_1.Top = 6
ComD_1.Width = 400
ComD_1.Height = 30
ComD_2.Left = 6
ComD_2.Top = 36
ComD_2.Width = 400
ComD_2.Height = 30
ComD_3.Left = 6
ComD_3.Top = 66
ComD_3.Width = 400
ComD_3.Height = 30
ComD_4.Left = 6
ComD_4.Top = 96
ComD_4.Width = 400
ComD_4.Height = 30
ComD_5.Left = 6
ComD_5.Top = 126
ComD_5.Width = 400
ComD_5.Height = 30
ComD_6.Left = 6
ComD_6.Top = 156
ComD_6.Width = 400
ComD_6.Height = 30
ComD_7.Left = 6
ComD_7.Top = 186
ComD_7.Width = 400
ComD_7.Height = 30

algo como
Código: [Seleccionar]
For n=1 to 7
ComD_n.Left = 6
ComD_n.Top = 6+(n-1)
ComD_n.Width = 400
ComD_n.Height = 30
next n

Espero que me puedan orientar sobre estos temas, gracias de antemano.
« Última modificación: 05 de Junio 2015, 08:33 por Mario R. Rancel »


 

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".