我有一个Excel代码,可以在菜单命令上创建按钮,这非常有效,但是,我现在想要包含一个XLA按钮但是当我加载xla时它永远不会工作,现在当我删除菜单命令代码时, xla的作品。我认为这是.reset函数的结果,它重置菜单并调用不包含xla命令的函数。所以我想问题是如何从宏中的子调用xla函数。
Private Sub createMenu()
'define the variables
Dim mnuDownload1 As Menu
Dim mnuDownload2 As Menu
Dim mnuDownload3 As Menu
Dim mnuDownload4 As Menu
'create the menue bar
With MenuBars(xlWorksheet)
.Reset
.Menus.Add "Import", 1
.Menus.Add "RAR", 1
.Menus.Add "Admin", 1
.Menus.Add "Install XLA", 1
'define the menue bar
Set mnuDownload1 = MenuBars(xlWorksheet).Menus("Import")
Set mnuDownload2 = MenuBars(xlWorksheet).Menus("RAR")
Set mnuDownload3 = MenuBars(xlWorksheet).Menus("Admin")
Set mnuDownload4 = MenuBars(xlWorksheet).Menus("Install XLA")
'for each defined menu bar at the sub item , the first "" is the name of the item. The second "" is the macro name
With mnuDownload1.MenuItems
.Add "Settings", "inputform_open"
.Add "Import", "RAR_Import"
End With
With mnuDownload2.MenuItems
.Add "RAR", "RAR"
End With
With mnuDownload3.MenuItems
.Add "Admin", "pass_open"
End With
With mnuDownload4.MenuItems
.Add "If the XLA is not available press here", "InstallAddIn"
End With
End With
End Sub
当书打开等时会运行。所以我认为.reset使XLA插件消失。