Menú de la ventana

Trucos VBA

Para añadir nuevas opciones al Menú de la ventana:

Abrimos un proyecto nuevo, y hacemos doble clic sobre el formulario. Mediante el gestor de menús escribimos lo siguiente:

  Caption -> Editor
  Name -> MnuEditor
  Pulse Insertar y el botón "->"
  Caption -> Añadir
  Name -> MnuAñadir
  Pulse Insertar
  Caption -> Quitar
  Name -> MnuQuitar
  Enabled -> False
  Pulse Insertar
  Caption -> Salir
  Name -> MnuSalir
  Pulse Insertar
  Caption -> -
  Name -> MnuIndex
  Index -> 0
  Pulse Aceptar

Escribir el siguiente código en el formulario:

  Private ultElem As Integer
  Private Sub Form_Load()
     ultElem = 0
  End Sub
  Private Sub MnuQuitar_Click()
     Unload MnuIndex(ultElem)
     ultElem = ultElem - 1
     If ultElem = 0 Then
        MnuQuitar.Enabled = False
     End If
  End Sub
  Private Sub MnuSalir_Click()
     End
  End Sub
  Private Sub MnuAñadir_Click()
     ultElem = ultElem + 1
     Load MnuIndex(ultElem)
     MnuIndex(ultElem).Caption = "Menu -> " + Str(ultElem)
     MnuQuitar.Enabled = True
  End Sub
Publicado en VBA