Академический Документы
Профессиональный Документы
Культура Документы
Copyright © 2015 por Cristian Rojas & “ESTA PAGINA ES OPCIONAL” Miguel
Gutiérrez. Todos los derechos reservados.
Tabla de Contenidos iii
Capítulo 1
y cuál es su funcionalidad.
Una vez concluida nuestra investigación procederemos a realizar una aplicación por
o Ingreso de la información de los estudiantes del curso con los datos de código y
nombre.
o Un módulo, donde el docente ingrese la nota por cada curso creado, por cada
Capítulo 2
o procesamiento de los datos existentes en Excel, o como una interfaz de usuario desde la
Estos formularios en Excel pueden ser empleados desde cualquier hoja, por medio
de algún botón que coloquemos, o desde la alguna Macro existente en Excel, para lo cual
de programador, se muestra una relación de macros que pueden ser empleadas, desde
dicha pantalla no existe más interacción relevante que solo seleccionar cuál de las macros
emplear, en cambio desde un Userform se pueden crear objetos como cajas de texto,
botones de opción, listas, etc, con las cuales se puede interactuar antes de proceder a
algún contenido en cualquiera de las hojas que encuentren en nuestro archivo Excel, o
.
3
Capítulo 3
Programador o Desarrollador, luego de ello seleccionar la opción “Visual Basic”, una vez
que nos encontremos en esta pantalla, sobre la ventana de Proyecto podemos realizar
seleccionar “Userform”.
Figura 1.
Luego se ello aparecerá un formulario en Excel en blanco, desde el cual se podrá añadir
Figura 2.
4
interfaces gráfica de usuario basadas en VBA (Visual Basic for Applications) en Excel.
5
Capítulo 4
Figura 3.
Ejemplo: Podemos poner un texto del tipo "Complete las opciones a continuación" y
Etiquta Label ubicarlo en cualquier sitio del UserForm.
Sirve para agrupar elementos de un UserForm (Los elementos se deben ubicar dentro
del Frame (Marco).
Si luego tenemos otro grupo de opciones del tipo Mayor de Edad/Menor de edad los
agrupamos dentro de otro Frame (Marco).
Es un simple Botón que nos permite ejecutar acciones.
Botón de Comando (CommandButton)
Ejemplo: Un Botón de Ayuda que ejecuta otro UserForm con ayuda para el usuario.
posibilidades.
Sirve para agrupar elementos de un UserForm (Los elementos se deben ubicar dentro
del Frame (Marco).
Si luego tenemos otro grupo de opciones del tipo Mayor de Edad/Menor de edad los
agrupamos dentro de otro Frame (Marco).
Es un simple Botón que nos permite ejecutar acciones.
Botón de Comando (CommandButton)
Ejemplo: Un Botón de Ayuda que ejecuta otro UserForm con ayuda para el usuario.
Página Multiple (MultiPage) Ejemplo: Un UserForm con 2 paginas: Nicaragua y el resto del Mundo.
Haciendo doble clic en cada control se abrirá una ventana donde podremos escribir y
asociarle una Macro.
7
Capítulo 5
Aplicación
desarrollo creativo ya que nos da la oportunidad de imaginar y ver todas las posibilidades
Codigo Impreso.
En la UserForm CoursesManager
Figura 4.
8
currentDelete = 0
Else
If indexrow = 0 Then
clearDataDelete
currentDelete = 0
Else
currentDelete = indexrow - 1
lblStatusQuery.Caption = "Encontrado"
lblCod.Caption = txtCodeToDelet.Text
lblName.Caption = tbl.Range.Cells(indexrow, 2)
lblSeats.Caption = tbl.Range.Cells(indexrow, 3)
End If
End If
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
tbl.ListRows(i).Delete
End If
Next
End Sub
End Sub
En la UserForm MainMenu.
StudentsHandlerForm.Show
End Sub
CoursesManagerForm.Show
End Sub
RatingsFormP.Show
End Sub
End Sub
En la UserForm RatingsForm
Figura 7
11
Public ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Cursos")
result = False
For i = 1 To tbl.Range.Cells.Count
result = True
13
Exit For
End If
Next
validateStudentId = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
result = False
For i = 1 To tbl.Range.Cells.Count
result = True
Exit For
End If
14
Next
validateCourse = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
result = False
For i = 1 To tbl.Range.Cells.Count
result = True
Exit For
End If
Next
validateRatingByStudentId = result
End Function
15
Set ws = ThisWorkbook.Worksheets("Cursos")
result = 0
For i = 1 To tbl.Range.Cells.Count
result = i
Exit For
End If
Next
getIndexRowByIdStudent = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
16
result = 0
For i = 1 To tbl.Range.Cells.Count
result = i
Exit For
End If
Next
getIndexRowToCode = result
End Function
Integer
Set ws = ThisWorkbook.Worksheets("Cursos")
result = 0
17
For i = 1 To tbl.Range.Cells.Count
result = i
Exit For
End If
Next
getIndexRowByIdStudentOnRatings = result
End Function
Sub clearAllFields()
txtCourseCodeSearch.Text = ""
lblCodeCourse.Caption = ""
lblCourseName.Caption = ""
lblCourseSeats.Caption = ""
currentCourseSelected = 0
currentQ1 = 0
currentQ2 = 0
18
currentQ3 = 0
currentCourseCode = ""
clearStudentFields
studentFrame.Visible = False
End Sub
Sub clearStudentFields()
txtStudentId.Text = ""
lblStudentId.Caption = ""
lblNameStudent.Caption = ""
txt1Q.Text = ""
txt2Q.Text = ""
txt3Q.Text = ""
lblPartialRating.Caption = ""
lblFInalRating.Caption = ""
lblQ1.Caption = ""
lblQ2.Caption = ""
lblQ3.Caption = ""
19
currentStudentSelected = 0
currentStudenId = ""
currentRating1 = 0
currentRating2 = 0
currentRating3 = 0
End Sub
backToMainMenu
End Sub
Sub backToMainMenu()
clearAllFields
Unload Me
End Sub
clearAllFields
End Sub
20
Set ws = ThisWorkbook.Worksheets("Cursos")
indexrow = getIndexRowToCode(txtCourseCodeSearch.Text)
currentCourseSelected = 0
clearAllFields
Else
If indexrow = 0 Then
clearAllFields
currentDelete = 0
Else
currentCourseSelected = indexrow - 1
lblCodeCourse.Caption = txtCourseCodeSearch.Text
lblCourseName.Caption = tbl.Range.Cells(indexrow, 2)
lblCourseSeats.Caption = tbl.Range.Cells(indexrow, 3)
21
currentCourseCode = txtCourseCodeSearch.Text
studentFrame.Visible = True
End If
End If
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
indexrow = getIndexRowByIdStudent(txtStudentId.Text)
currentStudentSelected = 0
clearStudentFields
Else
If indexrow = 0 Then
currentStudentSelected = 0
clearStudentFields
Else
currentStudenId = txtStudentId.Text
currentStudentSelected = indexrow - 1
lblStudentId.Caption = currentStudenId
tbl.Range.Cells(indexrow, 3)
getAndShowRatings
Else
currentStudentSelected = 0
clearStudentFields
End If
End If
End If
End Sub
Sub getAndShowRatings()
currentStudentsHasARatingRow = validateRatingByStudentId(currentStudenId)
If currentStudentsHasARatingRow Then
currentRatingIndex = getIndexRowByIdStudentOnRatings(currentStudenId)
currentRating1 = tbl.Range.Cells(currentRatingIndex, 4)
currentRating2 = tbl.Range.Cells(currentRatingIndex, 5)
currentRating3 = tbl.Range.Cells(currentRatingIndex, 6)
txt1Q = currentRating1
txt2Q = currentRating2
24
txt3Q = currentRating3
Else
End If
Else
End If
Else
End If
Else
End If
End If
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
currentRating1 = getOnlyDouble(txt1Q.Text)
currentRating2 = getOnlyDouble(txt2Q.Text)
26
currentRating3 = getOnlyDouble(txt3Q.Text)
currentRatingIndex = getIndexRowByIdStudentOnRatings(currentStudenId)
tbl.Range.Cells(currentRatingIndex, 4) = currentRating1
tbl.Range.Cells(currentRatingIndex, 5) = currentRating2
tbl.Range.Cells(currentRatingIndex, 6) = currentRating3
getAndShowRatings
Else
With newrow
.Range(2) = currentStudenId
27
.Range(3) = currentCourseCode
.Range(4) = currentRating1
.Range(5) = currentRating3
.Range(6) = currentRating3
End With
getAndShowRatings
Else
End If
End If
End Sub
result = 0
Else
28
result = CDbl(value)
Else
result = 0
End If
End If
getOnlyDouble = result
End Function
End Sub
En la UserForm StudentsHandler
Figura 7
29
Dim ws As Worksheet
allRigth = True
idStudent = txtIdStudent.Text
name = txtName.Text
lastName = txtLastName.Text
phone = txtPhone.Text
email = txtEmail.Text
course = txtCourse.Text
Set ws = ThisWorkbook.Worksheets("Cursos")
ws.Activate
If idStudent = "" Or name = "" Or lastName = "" Or phone = "" Or email = "" Or course =
"" Then
allRigth = False
Else
allRigth = False
End If
allRigth = False
End If
If validateStudentId(idStudent) Then
allRigth = False
End If
allRigth = False
End If
maxSeats = getMaxSeatsByCourse(course)
If maxSeats = 0 Then
allRigth = False
Else
allRigth = False
End If
End If
End If
If allRigth Then
With newrow
.Range(1) = idStudent
.Range(2) = name
.Range(3) = lastName
.Range(4) = phone
.Range(5) = email
.Range(6) = course
End With
clearFormToAddStudentTab
End If
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
result = False
34
For i = 1 To tbl.Range.Cells.Count
result = True
Exit For
End If
Next
validateStudentId = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
result = 0
For i = 1 To tbl.Range.Cells.Count
result = tbl.Range.Cells(i, 3)
Exit For
End If
Next
getMaxSeatsByCourse = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
result = 0
For i = 1 To tbl.Range.Cells.Count
result = result + 1
36
End If
Next
getStudentOnCourse = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
result = False
For i = 1 To tbl.Range.Cells.Count
result = True
Exit For
End If
Next
37
validateCourse = result
End Function
txtIdStudent.Text = ""
txtName.Text = ""
txtLastName.Text = ""
txtPhone.Text = ""
txtEmail.Text = ""
txtCourse.Text = ""
End Sub
lblStatusQuery.Caption = ""
lblIdStudent.Caption = ""
lblNameStudent.Caption = ""
lblCourseStudent.Caption = ""
txtIdStudentSerch.Text = ""
End Sub
backMainMenu
38
End Sub
clearFormToAddStudentTab
clearSerchFields
Unload Me
End Sub
backMainMenu
End Sub
clearFormToAddStudentTab
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
result = 0
For i = 1 To tbl.Range.Cells.Count
result = i
Exit For
End If
Next
getIndexRowByIdStudent = result
End Function
Set ws = ThisWorkbook.Worksheets("Cursos")
tbl.ListRows(currentDelete).Delete
clearSerchFields
currentDelete = 0
Else
clearSerchFields
End If
End Sub
Set ws = ThisWorkbook.Worksheets("Cursos")
indexrow = getIndexRowByIdStudent(txtIdStudentSerch.Text)
currentDelete = 0
41
clearSerchFields
Else
If indexrow = 0 Then
currentDelete = 0
clearSerchFields
Else
currentDelete = indexrow - 1
lblStatusQuery.Caption = "Encontrado"
lblIdStudent.Caption = txtIdStudentSerch.Text
tbl.Range.Cells(indexrow, 3)
lblCourseStudent.Caption = tbl.Range.Cells(indexrow, 6)
End If
End If
End Sub
End Sub
42
End Sub
Título 4. Las figuras pueden estar blanco y negro o a color. Si se usa color se
debe asegurar que la figura tenga sentido si se imprime a blanco y negro.En la figura 1 se
Lista de referencias
https://www.excel-avanzado.com/userform-en-excel
https://aplicaexcelcontable.com/blog/programar-en-excel-controles-de-un-userform.html