Bạn khởi động Excel, save lại với tên AddMenu.xls; nhấn Alt-F11 để mở Visual Basic.
Trong Visual Basic, chọn Insert/Module và chép đoạn code này vào
Sub ThemMenu()
Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, Temporary:=True)
newMenu.Caption = "&MyMenu" 'tao Menu moi co ten la MyMenu
Set ctrl1 = newMenu.CommandBar.Controls _
.Add(Type:=msoControlButton, Id:=1)
With ctrl1
.Caption = "Dong menu" 'menu cap 2
.Style = msoControlButton
.OnAction = "ExitMenu" 'goi macro ExitMenu
End With
End Sub
Sub ExitMenu()
On Error Resume Next
Application.CommandBars.ActiveMenuBar.Controls("&MyMenu").Delete
End Sub
Sub App_WorkbookDeactivate(ByVal Wb As Workbook)
'khi workbook nay (co ten AddMenu.xls) khong hien thi thi xoa MyMenu
Application.CommandBars.ActiveMenuBar.Controls("&MyMenu").Delete
End Sub
Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)
'Neu tro lai workbook nay (co ten AddMenu.xls) thi hien thi lai "MyMenu"
If Application.ActiveWindow.Caption = "ADDMENU.xls" Then
ThemMenu
End Sub