Compre
en línea y aproveche las espectaculares ofertas COMPAQ.
Eres el visitante
Nº
|
Como crear un Menú Personalizado en Excel.
Los
ejemplos mostrados en esta sección se encuentran comprimidos en formato *.zip.
Presione
aquí para descargar este ejemplo. menuexample97.zip
.
En
este ejemplo, se muestra como crear un menú personalizado que reemplaza al
menú existente por defecto en Excel.
El
siguiente código en VBA se encuentra en el Modulo1 del Editor de Visual Basic y
es el que crea el menú personalizado.
Para
ver el código desde el editor de Visual Basic, presione simultáneamente las
teclas ALT+F11, desde Excel.
Option Explicit
Sub CreateMenu()
Dim cb As CommandBar, cbMenu
As CommandBarControl, cbSubMenu As
CommandBarControl
DeleteCommandBar
Set cb = Application.CommandBars.Add("MyCommandBarName", msoBarTop,
True, True)
Set cbMenu = cb.Controls.Add(msoControlPopup, , , ,
True)
With cbMenu
.Caption = "&Mi menú"
.Tag = "MyTag"
.BeginGroup = False
End With
'Set cbMenu = Application.CommandBars.FindControl(, 30007) ' Menú-Herramientas
If cbMenu Is Nothing Then Exit Sub
With cbMenu.Controls.Add(msoControlButton, 1, , ,
True)
.Caption = "&MenuItem1"
.OnAction = ThisWorkbook.Name & "!Macroname"
End With
With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "&MenuItem2"
.OnAction = ThisWorkbook.Name & "!Macroname"
End With
Set cbSubMenu = cbMenu.Controls.Add(msoControlPopup, 1, , , True)
With cbSubMenu
.Caption = "&Submenu1"
.Tag = "SubMenu1"
.BeginGroup = True
End With
With cbSubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "&Submenu Item1"
.OnAction = ThisWorkbook.Name & "!Macroname"
.Style = msoButtonIconAndCaption
.FaceId = 71
.State = msoButtonDown
End With
With cbSubMenu.Controls.Add(msoControlButton, 1, , ,
True)
.Caption = "&Submenu Item2"
.OnAction = ThisWorkbook.Name & "!Macroname"
.Style = msoButtonIconAndCaption
.FaceId = 72
.Enabled = False
End With
Set cbSubMenu = cbSubMenu.Controls.Add(msoControlPopup, 1, , ,
True)
With cbSubMenu
.Caption = "&Submenu2"
.Tag = "SubMenu2"
.BeginGroup = True
End With
With cbSubMenu.Controls.Add(msoControlButton, 1, , ,
True)
.Caption = "&Submenu Item1"
.OnAction = ThisWorkbook.Name & "!Macroname"
.Style = msoButtonIconAndCaption
.FaceId = 71
.State = msoButtonDown
End With
With cbSubMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "&Submenu Item2"
.OnAction = ThisWorkbook.Name & "!Macroname"
.Style = msoButtonIconAndCaption
.FaceId = 72
.Enabled = False
End With
With cbMenu.Controls.Add(msoControlButton, 1, , ,
True)
.Caption = "&Eliminar este menú"
.OnAction = ThisWorkbook.Name & "!DeleteCommandBar"
.Style = msoButtonIconAndCaption
.FaceId = 463
.BeginGroup = True
End With
cb.Visible = True
Set cbSubMenu = Nothing
Set cbMenu = Nothing
Set cb = Nothing
End Sub
Sub DeleteCommandBar()
On Error Resume Next
Application.CommandBars("MyCommandBarName").Delete
On Error GoTo 0
End Sub
Sub Macroname()
MsgBox "Agregue aquí su código VBA!", vbInformation, ThisWorkbook.Name
End Sub
<---volver
|