Está en la página 1de 6

COLEGIO COMFANDI TULUA

INVESTIGACIÓN Y ARTE PARA HUMANIZAR LA VIDA


TECNOLOGIA E INFORMATICA
Docente: Ing. Lezly Jhovanna Carmona S
GRADO 11°
Semana 7- 10: 11 de marzo del 2019 – 05 de abril del 2019.

TEMA: FORMULARIOS_VBA_EXCEL

CÓDIGOS DE BOTONES Y MACROS PARA LOS EJERCICIOS 3 Y 4

EJERCICIO 3

 BOTÓN FINALIZAR CÓDIGO

Private Sub btn_Finalizar_Click()


End
End Sub

 BOTÓN REGISTRAR

Private Sub btn_Registrar_Click()


ActiveSheet.Cells(8, 1).Select
Selection.EntireRow.Insert
ActiveSheet.Cells(8, 1) = TextBox1
ActiveSheet.Cells(8, 2) = TextBox2
TextBox1 = Empty
TextBox2 = Empty

1
TextBox1.SetFocus
Ordenar ' Esta es la llamada de nuestra macro para ordenar los registros
End Sub

 MACRO AGREGAR

Se agrega este código en el módulo MODULO 1

Sub Agregar()
Load form_Clientes 'Cargamos el formulario
form_Clientes.Show 'Mostramos el formulario
End Sub

 MACRO ORDENAR (Está macro se graba en Excel) automáticamente aparece en el


modulo2

Sub Ordenar()
'
' Ordenar Macro
'

'
ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort.SortFields.Add _
Key:=Range("A8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom

2
.SortMethod = xlPinYin
.Apply
End With
End Sub

EJERCICIO 4

3
 BOTÓN FINALIZAR CÓDIGO

Private Sub btn_Finalizar_Click()


End
End Sub

 BOTÓN REGISTRAR

Private Sub btn_Registrar_Click()


ActiveSheet.Cells(8, 1).Select

Do While Not IsEmpty(ActiveCell)


ActiveCell.Offset(1, 0).Activate
Loop

ActiveCell.Offset(0, 0) = TextBox1
ActiveCell.Offset(0, 1) = TextBox2
ActiveCell.Offset(0, 2) = ComboBox1

TextBox1 = Empty
TextBox2 = Empty
ComboBox1 = Empty

TextBox1.SetFocus

' Ordenar ' Esta es la llamada de nuestra macro para ordenar los registros
End Sub

4
 CUADRO DE TEXTO CAMPO CARGO

Private Sub ComboBox1_Click()


ComboBox1 = Format(ComboBox1, "dd/mm/yyyy")
End Sub

 MACRO AGREGAR

Se agrega este código en el módulo MODULO 1

Sub Agregar()
Load form_Clientes 'Cargamos el formulario
form_Clientes.Show 'Mostramos el formulario
End Sub

 MACRO ORDENAR (Está macro se graba en Excel) automáticamente aparece en el


modulo2
Sub Ordenar()
'
' Ordenar Macro
'

'
ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort.SortFields.Add _
Key:=Range("A8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Hoja1").ListObjects("Tabla1").Sort
.Header = xlYes
.MatchCase = False

5
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

También podría gustarte