Вы находитесь на странице: 1из 2

APLICACIONDE VISUAL BASIC EN MACROS DE EXCEL

Crear la siguiente hoja de calculo



Colocare le nombre de inicio a la hoja


Seleccionar el rango de celda B6: D6 y colocarle el nombre de AGENDA
Crear una macros de nombre : AbrirFormAgregar

Se activa el editor de visual Basic, insertar un formulario, con el siguiente diseo





Hacer la codificacin para los botones de comando: Agregar y Cerrar
Private Sub CommandAgregar_Click( )
Dim nombre As String
Dim telefono As String
Dim correo As String
Dim mensaje As String
Dim rango As Range
Dim numFilas As Integer

nombre = Trim(TextNombre.Text)
telefono = Trim(TextTelefono.Text)
correo = Trim(TextCorreo.Text)

If nombre = "" Then mensaje = mensaje & "Falta el nombre" & vbCrLf
If telefono = "" Then mensaje = mensaje & "Falta el telfono" & vbCrLf
If correo = "" Then mensaje = mensaje & "Falta el correo" & vbCrLf

If mensaje <> "" Then
MsgBox mensaje, vbCritical
Exit Sub
End If
Insertar una
cuadro de texto

numFilas = Range("agenda").Rows.Count
Set rango = Range("agenda").Resize(1).Offset(numFilas)
rango.Cells(1).Value = nombre
rango.Cells(2).Value = telefono
rango.Cells(3).Value = correo
Range("agenda").Resize(numFilas + 1).Name = "agenda"
''Range("agenda").CurrentRegion.Name = "agenda"
TextNombre.Text = ""
TextTelefono.Text = ""
TextCorreo.Text = ""
TextNombre.SetFocus
End Sub

Private Sub CommandCerrar_Click( )
Unload FormAgregar
End Sub

el nombre del formulario es : FormAgregar
Escribir el siguiente cdigo en el modulo de la macros: AbrirFormAgregar()

Sub AbrirFormAgregar( )
FormAgregar.Show
End Sub
Seleccionar el cuadro de texto y asignar la macros de nombre: AbrirFormAgregar

Вам также может понравиться