|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub main() '????????????????????
Dim mybar As Object, arr, i&, j&, key$, myb, pkey$
Dim N_col As Long '?????????
On Error Resume Next
Set Tree = CreateObject("Scripting.Dictionary") '?????洢??????
Application.CommandBars("myCell").Delete '??????????????
Set mybar = Application.CommandBars.Add(Name:="myCell", position:=msoBarPopup) '????????????
Tree.Add "myCell", mybar
arr = Range("????!a1").CurrentRegion.Value '??λ??????,????????????arr
'??????,????д???????,???????????????ж????????key
N_col = UBound(arr, 2)
ReDim Preserve arr(1 To UBound(arr, 1), 1 To N_col + 1) '???????????????
'???????????????????????key
'Exit Sub
For i = 2 To UBound(arr) '???????????
If Not Tree.exists(arr(i, 1)) Then
If arr(i, 2) = "" Then '?????????????д?????
AddControlButton "myCell", arr(i, 1), arr(i, 1), i, N_col
Else '???????????????????
AddControlPopup "myCell", arr(i, 1), arr(i, 1)
End If
End If
key = arr(i, 1) '?????????п??
For j = 2 To N_col '????2-N??
If arr(i, j) <> "" Then '???????
pkey = key '?????????
key = key & "\" & arr(i, j) '?????????
If arr(i, j + 1) = "" Then '?????????????д?????
AddControlButton pkey, key, arr(i, j), i, N_col
Else '???????????????????
If Not Tree.exists(key) Then '????β??????
AddControlPopup pkey, key, arr(i, j)
End If
End If
End If
Next
Next
Set mybar = Nothing
End Sub |
|