1

我正在尝试使用在 PC 以及 Excel 2011 for Mac 上运行良好的插件。当我尝试在 Mac 上将它与 Excel 2019 一起使用时,我在尝试添加控件时收到上述错误消息。以下代码中的最后一行导致了问题:

Sub AddMenu()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCustomMenu As CommandBarControl
'Delete any existing one. We must use On Error Resume next in case it does not exist.
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&AS Tool").Delete
On Error GoTo 0
'Set a CommandBar variable to Worksheet menu bar
Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
'Return the Index number of the Help menu. We can then use this to place a custom menu before.
iHelpMenu = cbMainMenuBar.Controls("Help").Index
'Add a Control to the "Worksheet Menu Bar" before Help.
'Set a CommandBarControl variable to it
Set cbcCustomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpMenu)
'Give the control a caption
cbcCustomMenu.Caption = "&AS Tool"
'Working with our new Control, add a sub control and give it a Caption and tell it which macro to run (OnAction).
With cbcCustomMenu.Controls.Add(msoControlButton)

显然,msoControlPopup 不再支持 .controls.add。有已知的解决方法吗?

4

0 回答 0