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

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros

VBA para automatizar procesos

TALLER MACROS VBA EXCEL 2010


El formador dice y hace

VBA significa Visual Basic for Application. Es un lenguaje de programacin que surge de Visual Basic (VB). VBA de Excel est adaptado a Excel, para trabajar con celdas, hojas, autofiltro etc. (es decir, los objetos de la aplicacin Excel).

El Editor de Visual Basic (VBE)


El lenguaje de programacin que utiliza Excel para trabajar con macros es el VBA (Visual Basic Application) que como podemos deducir est basado en Visual Basic

El formador dice y el estudiante hace


PRACTICA 1
Ahora vamos a abrir un archivo de Excel nuevo y crearemos una macro VBA aplicada a una hoja de clculo donde insertaremos varios registros de clientes con sus datos bsicos con su clave de entrada correspondiente y aplicando un formulario de VBA, siga los pasos indicados a continuacin:

1. Trascribe la tabla (ver imagen) coloca los campos en el mismo sitio donde aparecen. 2. Ahora graba la macro grabada dando clic en el Botn de Office, colcale el nombre de TALLER CAJERO BANCO MACROS_VBA , luego en tipo de archivo, escoge la opcin LIBRO DE EXCEL HABILITADO PARA MACROS , fjate que te colocar el nombre del archivo asignado con la extensin . XLSM

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos

3. Ve al men programador y da clic en Editor de Visual Basic

donde luego le aparecer la ventana del

CREACION DE FORMULARIOS No. 1


4. Luego da clic en el men Insertar Userform y luego trascribe la siguiente macro: 5. En la ventana de Cuadro de Herramientas, inserta los siguientes controles : CINCO(5) = Botn de Comando (Command Button)

6. Ahora da doble clic en el botn INGRESAR CLIENTE Private Sub CommandButton1_Click() Unload Me UserForm1.Hide

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
UserForm2.Show End Sub

7. Ahora da doble clic en el botn CONSIGNAR Private Sub CommandButton2_Click() Unload Me UserForm1.Hide sw = 0 dato_ced = InputBox("INGRESE CEDULA", " CEDULA") dato_clave = InputBox("INGRESE CLAVE", "CLAVE") Range("C2").Select Do Until ActiveCell = "" ActiveCell.Offset(1, 0).Select If ActiveCell.Value = Val(dato_ced) Then If ActiveCell.Offset(0, 1).Value = Val(dato_clave) Then consignar = InputBox(" VALOR A CONSIGNAR", "CONSIGNAR") ActiveCell.Offset(0, 2).Select SALDO1 = ActiveCell.Value ActiveCell.Value = consignar + SALDO1 sw = 1 End If End If Loop If sw = 0 Then

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
MsgBox ("ERROR CLIENTE NO ENCONTRADO") Else MsgBox ("TRANSACCION EXITOSA") End If End Sub

8. Ahora da doble clic en el botn RETIRAR Private Sub CommandButton3_Click() Unload Me UserForm1.Hide sw = 0 dato_ced = InputBox("INGRESE CEDULA", " CEDULA") dato_clave = InputBox("INGRESE CLAVE", "CLAVE") Range("C2").Select Do Until ActiveCell = "" ActiveCell.Offset(1, 0).Select If ActiveCell.Value = Val(dato_ced) Then If ActiveCell.Offset(0, 1).Value = Val(dato_clave) Then RETIRAR = InputBox(" VALOR A RETIRAR", "RETIRAR") ActiveCell.Offset(0, 2).Select SALDO1 = ActiveCell.Value If SALDO1 >= Val(RETIRAR) Then ActiveCell.Value = SALDO1 - Val(RETIRAR) sw = 1

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
Else MsgBox ("FONDOS INSUFICIENTES") Exit Do End If End If End If Loop If sw = 0 Then MsgBox ("ERROR CLIENTE NO ENCONTRADO") Else MsgBox ("TRANSACCION EXITOSA") End If End Sub

9. Ahora da doble clic en el botn CONSULTAR SALDO Private Sub CommandButton4_Click() Unload Me UserForm1.Hide sw = 0 dato_ced = InputBox("INGRESE CEDULA", " CEDULA") dato_clave = InputBox("INGRESE CLAVE", "CLAVE") Range("C2").Select Do Until ActiveCell = "" ActiveCell.Offset(1, 0).Select

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
If ActiveCell.Value = Val(dato_ced) Then If ActiveCell.Offset(0, 1).Value = Val(dato_clave) Then ActiveCell.Offset(0, 2).Select SALDO1 = ActiveCell.Value MsgBox " SALDO" & " " & SALDO1 sw = 1 End If End If Loop If sw = 0 Then MsgBox ("ERROR CLIENTE NO ENCONTRADO") Else MsgBox ("TRANSACCION EXITOSA") End If End Sub

10. Ahora da doble clic en el botn SALIR Private Sub CommandButton5_Click() End End Sub

CREACION DE FORMULARIOS No. 2


6. Luego da clic en el men Insertar - Userform y luego trascribe la siguiente macro: 7. En la ventana de Cuadro de Herramientas, inserta los siguientes controles :

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
CUATRO (4) ETIQUETAS = LABEL CUATRO (4) CUADROS DE TEXTOS = TEXTBOX DOS (2) COMANDOS = COMMAND BUTTON

11. Ahora da doble clic en el botn SALIR

Private Sub SALIR_Click() Unload Me UserForm1.Hide End Sub

12. Ahora da doble clic en el botn INGRESAR Private Sub INGRESAR_Click() Selection.EntireRow.Insert 'Vaca los cuadros de textos digitados TextBox1 = Empty TextBox2 = Empty TextBox3 = Empty TextBox4 = Empty

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
TextBox1 = SetFocus End Sub

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 = Val(TextBox3) End Sub

Private Sub TextBox4_Change() Range("D2").Select ActiveCell.FormulaR1C1 = Val(TextBox4) End Sub

INCAP INSTITUTO COLOMBIANO DE APRENDIZAJE TALLER LOGRO 3 TEMA: Macros Visual Basic Application OBJETIVOS: Aprender y disear macros VBA para automatizar procesos
13. Luego vamos a insertar un control de Botn de comando en la hoja de clculo de Excel, para ello da clic en el men Programador de Excel y luego selecciona Insertar y da clic en la seccin de Controles Active X y escoge Botn de comando (Command Button) Luego da clic en el men Insertar - Modulo y luego trascribe la siguiente macro: 14. A continuacin dele clic derecho seleccione Objeto de Comando y seleccione Modifica y escriba MENU PRINCIPAL 15. Ahora dele doble clic para abrir el Editor de Visual Basic (VBE), y aparecer el ttulo: Private Sub Matricula_click(), ahora escriba el siguiente cdigo: Private Sub CommandButton1_Click() UserForm1.Show End Sub

16. Para ejecutar la macro finalmente vaya al men Programador y dele clic en el icono Modo de diseo macro sin ningn problema para salir de ese modo y ahora si podr aplicar la

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