我正在尝试创建一个带有多个子项的Excel加载项命令栏。子项目名称在不同的工作表上列出,因此不同的组可以使用此文件。这部分似乎工作正常。问题是,当您单击子项时,我无法运行宏。宏(MechAssign1)自身运行良好。这是代码:
Private Sub Worksheet_Activate()
On Error Resume Next ' In case there are no blanks
Columns("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Dim Ref1 As String
Dim Ref2 As String
Dim Ref3 As String
Dim Ref4 As String
Dim Ref5 As String
Dim Ref6 As String
Dim Ref7 As String
Dim Ref8 As String
Ref1 = Sheets("Set Up Tab").Range("B2").Value
Ref2 = Sheets("Set Up Tab").Range("B3").Value
Ref3 = Sheets("Set Up Tab").Range("B4").Value
Ref4 = Sheets("Set Up Tab").Range("B5").Value
Ref5 = Sheets("Set Up Tab").Range("B6").Value
Ref6 = Sheets("Set Up Tab").Range("B7").Value
Ref7 = Sheets("Set Up Tab").Range("B8").Value
Ref8 = Sheets("Set Up Tab").Range("B9").Value
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref1.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref2.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref3.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref4.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref5.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref6.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref7.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Controls.Ref8.Delete
CommandBars("Worksheet menu bar").Controls("Assign To").Delete
Dim newMenu As Object
Set newMenu = CommandBars("Worksheet menu
bar").Controls.Add(Type:=msoControlPopup, Temporary:=True)
With newMenu
.Caption = "Assign To"
End With
Dim subItem1 As Object
Set subItem1 = CommandBars("Worksheet menu bar").Controls("Assign To")
With subItem1
.Controls.Add(Type:=msoControlButton, Temporary:=True).Caption =
Ref1
.Controls.[Ref1].OnAction = "'MechAssign1 "
End With