Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ejercicio 1:
TextBox1
TextBox2
TextBox3
CommandButton1
CAJAS DE TEXTO
Private Sub TextBox1_Change()
Range("A2").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
Private Sub TextBox2_Change()
Range("B2").Select
ActiveCell.FormulaR1C1 = TextBox2
End Sub
Private Sub TextBox3_Change()
Range("C2").Select
ActiveCell.FormulaR1C1 = TextBox3
End Sub
BOTN DE INSERTAR
Private Sub CommandButton1_Click()
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox1.SetFocus
End Sub
UFNombre
UFEdad
UFFecha
|
Uf_Agregar
CommandButton2
CAJAS DE TEXTO
Private Sub UFNombre_Change()
Range("A3").Select
ActiveCell.FormulaR1C1 = UFNombre
End Sub
Private Sub UFEdad_Change()
Range("B3").Select
ActiveCell.FormulaR1C1 = UFEdad
End Sub
Private Sub UFFecha_Change()
Range("C3").Select
ActiveCell.FormulaR1C1 = UFFecha
End Sub
TextBox1
TextBox2
TextBox3
CommanBotton
CAJAS DE TEXTO
Private Sub TextBox1_Change()
Range("A2").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
BOTN DE RESULTADO
Private Sub CommandButton1_Click()
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub
TextBox1
TextBox2
TextBox3
TextBox4
TextBox5
CommandButton
CAJAS DE TEXTO
Private Sub TextBox1_Change()
Range("A3").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
BOTN INSERTAR
Private Sub CommandButton1_Click()
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
TextBox1.SetFocus
End Sub
CAJA DE TEXTO
Private Sub TextBox1_Change()
Range("A3").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
CUADROS DE TEXTO
Private Sub TextBox1_Change()
Range("A3").FormulaR1C1 = TextBox1
Rem esta primer lnea reemplaza a estas dos que te parece todava ms corta
Range ("A3").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
BOTON DE CONSULTA
Private Sub CommandButton1_Click()
On Error Goto noencontro
Rem esta lnea genera una trampa de error si Excel encuentra un error se le dice que se vaya a
la etiqueta noencontro que esta definida mas adelante en el cdigo. No use la trampa de error
si no tiene problemas a la hora de que no encuentra a la persona. Recuerde si usted comete
cualquier error Excel se dirigir a la etiqueta noencontro.y esquivara cualquier error, hasta
uno que usted cometa en la programacin.
Cells.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Select
TextBox2 = ActiveCell
ActiveCell.Offset(0, 1).Select
TextBox3 = ActiveCell
Rem Tambin se puede utilizar este cdigo para leer la informacin de las celdas lo que esta
en azul. La diferencia es que se asignan los valores a variables y despus se descargan a los
TextBoxs.
ActiveCell.Offset(0, 1).Select
Direccion = Activecell
ActiveCell.Offset(0, 1).Select
Telefono = Activecell
TextBox2 = Direccion
TextBox3 = Telefono
noencontro:
Rem Aqu se esquiva el error
End Sub
BOTON BAJA
Private Sub CommandButton2_Click()
Selection.EntireRow.Delete
Range("A3").Select
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub
BOTON INSERTAR
Private Sub CommandButton3_Click()
Range("A3").Select
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub
CUADRO DE TEXTO:
Private Sub TextBox1_Change()
Range("A3").Select
ActiveCell.FormulaR1C1 = TextBox1
End Sub
CUADRO COMBINADO:
Private Sub ComboBox1_Change()
Range("B3").Select
ActiveCell.FormulaR1C1 = ComboBox1
End Sub
CUADRO DE LISTA:
Private Sub ListBox1_Click()
Range("C3").Select
ActiveCell.FormulaR1C1 = ListBox1
End Sub
BOTN INSERTAR:
Private Sub CommandButton1_Click()
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox1.SetFocus
End Sub
BOTN CERRAR:
Private Sub CommandButton2_Click()
Unload Me
End Sub
Nota:
Para cargar automticamente los elementos del ListBox y comboBox debes ir al final del cdigo y
pegar lo siguiente:
Private Sub UserForm_Activate()
Rem: Cargar los elementos del Combobox
ComboBox1.AddItem "Femenino"
ComboBox1.AddItem "Masculino"
Rem: Ahora los listbox
ListBox1.AddItem "ventas"
ListBox1.AddItem "Compras"
ListBox1.AddItem "Recursos Humanos"
ListBox1.AddItem "Contabilidad"
End Sub
Label8, colocar en su
interior el nmero 2
CAJAS DE TEXTO:
TextBox5 = ActiveCell
ActiveCell.Offset(0, 1).Select
TextBox6 = ActiveCell
ActiveCell.Offset(0, 1).Select
TextBox7 = ActiveCell
Rem la etiqueta 4 toma el valor del rengln activo y permite modificar la informacin que
encontr, ya que modifiques la informacin presionas el botn actualizar.
Label8 = ActiveCell.Row
noencontro:
End Sub
Botn modificar
Private Sub CommandButton3_Click()
Rem Vuelve a indicar el rengln 9 para escribir en los Textboxs
Label8 = "2"
Range("A2").Select
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
TextBox6 = Empty
TextBox1.SetFocus
End Sub
Debes ingresar al cdigo, ubicarse al final y agregar el siguiente cdigo para que aparezcan
automticamente las opciones en el combobox.
Private Sub UserForm_Activate()
ComboBox1.AddItem "Femenino"
ComboBox1.AddItem "Masculino"
End Sub
Ejercicio 9: Disea un formulario que permita consultar y modificar el dato que se encontr
Ver solucin paso a paso en pgina 41 del documento GUIA06COM118_Macros_2012.pdf.
Botn insertar:
Private Sub CommandButton1_Click()
Rem si no se escribe nada en los Textboxs a la hora de insertar escribe No Tiene
If TextBox1 = Empty Then Range("A2").FormulaR1C1 = "No Tiene"
If TextBox2 = Empty Then Range("B2").FormulaR1C1 = "No Tiene"
If TextBox3 = Empty Then Range("C2").FormulaR1C1 = "No Tiene"
Range("A2").Select
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub
Botn Consulta:
Private Sub CommandButton2_Click()
On Error GoTo noencontro
Rem Cdigo para buscar, ya lo conocemos
Cells.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Select
TextBox2 = ActiveCell
ActiveCell.Offset(0, 1).Select
TextBox3 = ActiveCell
Rem la etiqueta 4 toma el valor del rengln activo y permite modificar la informacin que
encontr, ya que modifiques la informacin presionas el botn actualizar.
Label4 = ActiveCell.Row
noencontro:
End Sub
Botn Actualizar:
Caja de texto1:
Private Sub TextBox1_Change()
Range("A" + Label4).FormulaR1C1 = TextBox1
End Sub
Caja de texto2:
Private Sub TextBox2_Change()
Range("B" + Label4).FormulaR1C1 = TextBox2
End Sub
Caja de texto3:
Private Sub TextBox3_Change()
Range("C" + Label4).FormulaR1C1 = TextBox3
End Sub