Advertisement
kijato

Excel, VBA, CustomMenu

May 7th, 2020
1,705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '
  2. ' Forrás: EXCEL PROGRAMOZÁS (Pusztai Pál)
  3. '
  4.  
  5. 'Saját menü létrehozás
  6. Sub MenuKirak()
  7.     MenuLevesz
  8.     Dim fomenu As CommandBar
  9.     Dim fomenupont As CommandBarControl, almenupont As CommandBarControl
  10.     Set fomenu = Application.CommandBars.ActiveMenuBar
  11.     'Egy új (felbukkanó) menüpont létrehozása
  12.    Set fomenupont = fomenu.Controls.Add(Type:=msoControlPopup)
  13.     fomenupont.Caption = "Menü"
  14.     'Az új főmenüponthoz egy új almenüpontot
  15.    Set almenupont = fomenupont.CommandBar.Controls.Add(Type:=msoControlButton)
  16.     almenupont.Caption = "Form megjelenítés"
  17.     'A menüpont aktivizálásakor lefutó szubrutin
  18.    almenupont.OnAction = "ThisWorkbook.FormKirak"
  19. End Sub
  20.  
  21. Sub FormKirak()
  22.     'UserForm1.Show vbModal
  23.    UserForm1.Show vbModeless
  24. End Sub
  25.  
  26. 'Saját menü levétele
  27. Sub MenuLevesz()
  28.     Dim menupont As CommandBarControl
  29.     For Each menupont In Application.CommandBars.ActiveMenuBar.Controls
  30.       If menupont.Caption = "Menü" Then
  31.         menupont.Delete
  32.       End If
  33.     Next
  34. End Sub
  35.  
  36. 'Az eredeti rendszermenü visszaállítása (ha elrontanánk a menüt)
  37. Sub MenuAlaphelyzet()
  38.     Application.CommandBars("Worksheet Menu Bar").Reset
  39. End Sub
  40.  
  41. Private Sub Workbook_Deactivate()
  42.  
  43. End Sub
  44.  
  45. Private Sub Workbook_Open()
  46.  
  47. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement