|
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim oPopup As CommandBar
Dim oSubMenu As CommandBarPopup
Dim oMenuItem As CommandBarControl
Set d = CreateObject("scripting.dictionary")
Cancel = True
On Error Resume Next
CommandBars("TeacherMenu").Delete
On Error GoTo 0
Set oPopup = CommandBars.Add("TeacherMenu", msoBarPopup)
Set oSubMenu = oPopup.Controls.Add(msoControlPopup)
oSubMenu.Caption = "教师姓名"
For i = 1 To 11
Set oMenuItem = oSubMenu.Controls.Add(msoControlPopup)
oMenuItem.Caption = Sheets(2).Cells(1, i)
d.RemoveAll
For j = 2 To Sheets(2).Cells(65536, Sheets(2).Rows(1).Find(Sheets(2).Cells(1, i), , , xlWhole).Column).End(xlUp).Row
If Not d.exists(Sheets(2).Cells(j, i).Value) And Sheets(2).Cells(j, i).Value <> "" Then
d(Sheets(2).Cells(j, i).Value) = Sheets(2).Cells(j, i).Value
With Application.CommandBars("TeacherMenu").Controls(1).Controls(i).Controls.Add(Type:=msoControlButton)
.Caption = Sheets(2).Cells(j, i).Value
.OnAction = "rtclick"
End With
End If
Next
Next
oPopup.ShowPopup
oPopup.Delete
End Sub |
|