excel-vba中的多级弹出框

时间:2017-03-27 01:28:01

标签: excel vba excel-vba

大家好日子,

我正在为我的工作创建一个excel模板,我能够按照本教程让我创建一个弹出菜单,但我希望它有两层。基本上如果按下按钮,第一周到第四周就会弹出,当我按第一周时,周一到周五会弹出。希望这是有道理的。请帮忙。

示例:

Button
  Week 1
     Monday
     Tuesday
     Wednesday
  Week 2
  Week 3
  Week 4

我不是一个真正的程序员,我只是想学习一些VB应用程序,只是为了减轻我的一些任务。我也是新来的,所以对我来说很容易大声笑。

谢谢!

Public The_Menu As CommandBar
Function CreateSubMenu() As CommandBar

Const pop_up_menu_name = "Pop-up Menu"

Dim the_command_bar As CommandBar
Dim the_command_bar_control As CommandBarControl

'Deletes any CommandBars that may be present
For Each menu_item In CommandBars
If menu_item.Name = pop_up_menu_name Then
CommandBars(pop_up_menu_name).Delete
End If
Next

''Add our popup menu to the CommandBars collection
Set the_command_bar = CommandBars.Add(Name:=pop_up_menu_name, Position:=msoBarPopup, MenuBar:=False, Temporary:=False)

'*****Menu Options*****
Set the_command_bar_control = the_command_bar.Controls.Add
the_command_bar_control.Caption = "Week 1"
the_command_bar_control.OnAction = "Week1"

Set the_command_bar_control = the_command_bar.Controls.Add
the_command_bar_control.Caption = "Week 2"
the_command_bar_control.OnAction = "Week2"

Set the_command_bar_control = the_command_bar.Controls.Add
the_command_bar_control.Caption = "Week 3"
the_command_bar_control.OnAction = "Week3"

Set the_command_bar_control = the_command_bar.Controls.Add
the_command_bar_control.Caption = "Week 4"
the_command_bar_control.OnAction = "Week4"

Set the_command_bar_control = the_command_bar.Controls.Add
the_command_bar_control.Caption = "Week 5"
the_command_bar_control.OnAction = "Week5"


'To add more items to the menum simply copy the 3 lines above and paste below

'All you need to do is change the caption and onaction macro names.

Set CreateSubMenu = the_command_bar

End Function

0 个答案:

没有答案