martes, 22 de junio de 2010

Un menú sencillo en excel.

Procedimiento
Abra un libro en Excel
Active en la cinta de menus la opción de Programador.
en la hoja1 ubique las siguientes palabras, que se verán como un menú a la hora de hacerle click a cada palabra: celda 1,1 ubique la palabra opcion1; en la 1,2 opcion2, y asíi sucesivamente hasta opcion4
Vaya a la opción de macros de men{u programador y abra el editor de Visual Basic
Dar doble click a la hoja1 y seleccinar WorkSheet en la parte del menú desplegable que dice General.
en worksheet, en la parte derecua desplegar la opción o evento SlectionChange. Allí ubicar el siguiente código:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
fila = Target.Row
columna = Target.Column


For columnax = 1 To 6
If fila = 1 And columna = columnax Then
Hoja1.Cells(1, 1) = "Estudiantes"
Hoja1.Cells(1, 2) = "Profesores"
Hoja1.Cells(1, 3) = "IH"
Hoja1.Cells(1, 4) = "Logros"
Hoja1.Cells(1, 5) = "Notas"
For k = 1 To 6
If k = columnax Then
'Hoja1.Cells(1, k).Font.Size = 14
Hoja1.Cells(1, k) = "(" & Hoja1.Cells(1, k) & ")"
If k = 1 Then
Hoja1.Cells(2, 1) = "Nuevo"
Hoja1.Cells(2, 2) = "Modificar"
Hoja1.Cells(2, 3) = "Eliminar"
Hoja1.Cells(2, 3) = "Buscar"
End If
If k = 2 Then
Hoja1.Cells(2, 1) = "Nuevo p "
Hoja1.Cells(2, 2) = "Modificar p"
Hoja1.Cells(2, 3) = "Eliminar p"
Hoja1.Cells(2, 3) = "Buscar p"
End If
If k = 3 Then
Hoja1.Cells(2, 1) = "ih1"
Hoja1.Cells(2, 2) = "ih2"
Hoja1.Cells(2, 3) = "ih3"
Hoja1.Cells(2, 3) = "ih4"
End If
If k = 4 Then
Hoja1.Cells(2, 1) = "l1"
Hoja1.Cells(2, 2) = "l2"
Hoja1.Cells(2, 3) = "l3"
Hoja1.Cells(2, 3) = "l4"
End If
If k = 5 Then
Hoja1.Cells(2, 1) = "n1"
Hoja1.Cells(2, 2) = "n2"
Hoja1.Cells(2, 3) = "n3"
Hoja1.Cells(2, 3) = "n4"
End If
End If
Next k
End If
Next columnax

For columnax = 1 To 6
If fila = 2 And columna = columnax And Hoja1.Cells(1, 1) = "(Estudiantes)" Then
Hoja1.Cells(2, 1) = "Nuevo"
Hoja1.Cells(2, 2) = "Modificar"
Hoja1.Cells(2, 3) = "Eliminar"
Hoja1.Cells(2, 3) = "Buscar"
For k = 1 To 6
If k = columnax Then
If Hoja1.Cells(2, k) <> "" Then Hoja1.Cells(2, k) = "((" & Hoja1.Cells(2, k) & "))"
End If
Next k
End If
Next columnax
For columnax = 1 To 6
If fila = 2 And columna = columnax And Hoja1.Cells(1, 2) = "(Profesores)" Then
Hoja1.Cells(2, 1) = "Nuevo p"
Hoja1.Cells(2, 2) = "Modificar p"
Hoja1.Cells(2, 3) = "Eliminar p"
Hoja1.Cells(2, 3) = "Buscar p"
For k = 1 To 6
If k = columnax Then
If Hoja1.Cells(2, k) <> "" Then Hoja1.Cells(2, k) = "((" & Hoja1.Cells(2, k) & "))"
End If
Next k
End If
Next columnax




End Sub

Ojo, no copiar ni la primera fila ni la ultima, es decir ni private ni end sub

Verifique que funcione dando clic en la hoja1 en las palabras opcion1, opcion2 y verá como se comporta como una barra de menús.

Datos personales