|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub DeleteMycell() '还原右键菜单
- Application.CommandBars("cell").Reset
- End Sub
- Sub CreatMe() '生成右键菜单
- Dim d As Object, ds As Object, i&, j&, k, k2, k3, l&, arr
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- arr = Sheets("Sheet1").Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- If Not d.Exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- If Len(arr(i, 2)) Then
- d(arr(i, 1))(arr(i, 2)) = ""
- If Not ds.Exists(arr(i, 1) & arr(i, 2)) Then Set ds(arr(i, 1) & arr(i, 2)) = CreateObject("scripting.dictionary")
- If Len(arr(i, 3)) Then ds(arr(i, 1) & arr(i, 2))(arr(i, 3)) = ""
- End If
- Next
- k = d.keys
- With Application.CommandBars("cell")
- .Reset '重置右键菜单,以免因多次运行重复添加
- .Controls("删除(&D)...").Delete '
- .Controls("复制(&C)").Delete '
- .Controls("粘贴(&P)").Delete '
- .Controls("剪切(&T)").Delete '删除右键菜单中的剪切菜单
- .Controls("清除内容(&N)").Delete '
- .Controls("从下拉列表中选择(&K)...").Delete '
- .Controls("选择性粘贴(&S)...").Delete '
- .Controls("添加监视点(&W)").Delete '
- .Controls("创建列表(&C)...").Delete '
- .Controls("超链接(&H)...").Delete '
- .Controls("查阅(&L)...").Delete '
- For i = 0 To UBound(k)
- With .Controls.Add(Type:=msoControlPopup)
- .Caption = k(i)
- .OnAction = ""
- .BeginGroup = True '分组显示
- k2 = d(k(i)).keys
- For j = 0 To UBound(k2)
- With .Controls.Add(Type:=msoControlPopup)
- .Caption = k2(j)
- .OnAction = ""
- k3 = ds(k(i) & k2(j)).keys
- For l = 0 To UBound(k3)
- With .Controls.Add(Type:=msoControlPopup)
- .Caption = k3(l)
- .OnAction = ""
- End With
- Next
- End With
- Next
- End With
- Next
- End With
-
- End Sub
复制代码 |
|