Sei sulla pagina 1di 4

FORMULARIO DE EXCEL - EDITOR DE VBA Pasos para Crear Un Diseo De Formulario: Lo primero que se debe hacer es ingresar al Microsoft

t Excel 2010,y Disear La Siguiente Lista De


EMPLEADOS En Una Hoja Nueva Llamada CONTROL DE EMPLEADOS:

luego presionar las teclas ALT + F11, y se mostrara la ventana de Editor De Visual Basic VBA. Luego Ir Al Men Insertar UserForm.

Luego Insertar Los Siguientes Sobre El Formulario: *- 7 ETIQUETAS. *- 1 CUADRO COMBINADO. *- 5 CUADROS DE TEXTO. *- 2 BOTONES DE COMANDO.

El Diseo Se Mostrara As:

Utilizar La PROPIEDAD CAPTION, Para Los Controles LABEL o Etiquetas. Utilizar La PROPIEDAD NAME, Para Los Controles TEXTBOX o Cuadro De Texto. Utilizar La PROPIEDAD NAME, Para Los Controles COMMANDBUTTON o Boton De Comando. Utilizar La PROPIEDAD NAME, Para El Formulario, Su Nombre Sera: FRMINGRESO.

Prof: Mauico Flores, Roly. Cell: 9 - 9233 - 7013

P g i n a |1

Sede: ATE LOS OLIVOS E-Mail: Roly_1587@hotmail.com

Microsoft Office Excel 2007

Luego realizar Doble Clic En El Formulario y Ubicar El Evento Initialize(), y Copiar El Siguiente Codigo:

Private Sub UserForm_Initialize() Cargamos Los Datos En El Cuadro Combinado CBSEXO.AddItem ("Masculino") CBSEXO.AddItem ("Femenino") 'Autogeneramos El Numero Worksheets("CONTROL DE EMPLEADOS").Activate Range("B4").Select If ActiveCell = Empty Then TXTNUMERO.Enabled = False TXTNUMERO.Text = 1 Else Range("B2").End(xlDown).Select TXTNUMERO.Enabled = False TXTNUMERO.Text = ActiveCell.Value + 1 End If End Sub Luego realizar Doble Clic En El Formulario y Ubicar El Evento QueryClosey Copiar El Siguiente Codigo:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Anulamos El Boton Cerrar (X), y Solo Cerraremos El Formulario Con El Boton SALIR. If CloseMode = vbFormControlMenu Then Cancel = True MsgBox ("Utilize El Boton Salir") End If End Sub Luego realizar Doble Clic En El BOTON SALIR y Copiar El Siguiente Codigo:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Anulamos El Boton Cerrar (X), y Solo Cerraremos El Formulario Con El Boton SALIR. Dim Mensaje As String Mensaje = MsgBox("Desea Salir", vbQuestion + vbYesNo, "Aviso") If Mensaje = vbYes Then Unload Me End If End Sub
Prof: Mauico Flores, Roly. Cell: 9 - 9233 - 7013 Sede: ATE LOS OLIVOS E-Mail: Roly_1587@hotmail.com

P g i n a |2

Microsoft Office Excel 2007

Luego realizar Doble Clic En El BOTON INGRESAR y copiar los siguiente cdigos:

Private Sub CmdIngresar_Click() Verificamos Que Todos Los Campos Esten Llenos If TXTNOMBRE = "" Or TXTDIRECCION = "" Or TXTTELEFONO = "" Or CBSEXO = "" Or TXTEDAD = "" Then MsgBox ("Ingrese Todos Los Datos...!") Exit Sub End If 'Verificamos Que El Campo De Edad Sea Numerico If Not IsNumeric(TXTEDAD) Then MsgBox ("Ingrese Una Edad Numerica...!") TXTEDAD.Text = "" Exit Sub End If 'Verificamos Que Se Ingrese Una Edad Razonable If TXTEDAD.Value <= 0 Or TXTEDAD.Value > 60 Then MsgBox ("Ingrese Una Edad Adecuada...!") TXTEDAD.Text = "" Exit Sub End If 'Comensamos El Ingreso De Los Datos. Sheets("CONTROL DE EMPLEADOS").Activate Range("B2").Select If ActiveCell.Offset(1, 0).Value = "" Then Exit Sub End If Selection.End(xlDown).Activate ActiveCell.Offset(1, 0).Activate ActiveCell.Value = Val(TXTNUMERO.Text) ActiveCell.Offset(0, 1).Value = TXTNOMBRE.Text ActiveCell.Offset(0, 2).Value = TXTDIRECCION.Text ActiveCell.Offset(0, 3).Value = TXTTELEFONO.Text ActiveCell.Offset(0, 4).Value = CBSEXO.Text ActiveCell.Offset(0, 5).Value = Val(TXTEDAD.Text) 'Aqui Volvemos A Autogenerar El Codigo Range("B2").End(xlDown).Select TXTNUMERO.Text = ActiveCell.Value + 1 'Limpia Las Cajas De Texto Para Un Nuevo Ingreso TXTNOMBRE.Text = "" TXTDIRECCION.Text = "" TXTTELEFONO.Text = "" CBSEXO.Text = "" TXTEDAD.Text = "" TXTNOMBRE.SetFocus End Sub
Prof: Mauico Flores, Roly. Cell: 9 - 9233 - 7013 Sede: ATE LOS OLIVOS E-Mail: Roly_1587@hotmail.com

P g i n a |3

Microsoft Office Excel 2007

Luego Ir Al Men Insertar MODULO.

En la ventana que se muestra crear el Siguiente Procedimiento:

Luego Activar La Ficha Programador e Insertar 2 Controles Botn(Controles De Formulario) y Asignarle Los procedimientos Creados (Limpiar_Filas Llamar_Formulario), que en realidad es UNA MACRO que Limpia Un Fila Seleccionada y La Otra Llama Al Formulario Diseado:

Luego realizar 12 ingresos Para Probar Nuestro Formulario Creado. Luego Limpiar 4 Registros Para Probar El BOTON ELIMINAR REGISTRO SELECCIONADO. Luego Proteger La Hoja De Excel 2007 FICHA REVISAR BOTON PROTEGER HOJA, Asignarle Una Contrasea.
Sede: ATE LOS OLIVOS E-Mail: Roly_1587@hotmail.com

Prof: Mauico Flores, Roly. Cell: 9 - 9233 - 7013

P g i n a |4

Microsoft Office Excel 2007

Potrebbero piacerti anche