|
其实你2楼的附件中那么多的语句可以简化如下:
Private Sub Workbook_Open()
On Error Resume Next
Application.CommandBars("自定义工具栏").Delete
With Application.CommandBars.Add("自定义工具栏", msoBarTop)
With .Controls.Add(msoControlPopup)
.Caption = "竞赛项目"
Set d = CreateObject("scripting.dictionary")
arr = Sheet2.UsedRange
For i = 2 To UBound(arr)
If arr(i, 2) = "" Then Exit For
If Not d.exists(arr(i, 2)) Then '
.Controls.Add(msoControlPopup).Caption = arr(i, 2)
d(arr(i, 2)) = ""
End If
If Not d.exists(arr(i, 2) & arr(i, 3)) Then
With .Controls(arr(i, 2)).Controls.Add(msoControlButton)
.Caption = arr(i, 3)
.OnAction = arr(i, 3)
End With
d(arr(i, 2) & arr(i, 3)) = ""
End If
Next
Set d = Nothing
End With
With .Controls.Add(msoControlPopup)
.Caption = "关闭系统"
With .Controls.Add(msoControlButton)
.Caption = "关闭系统"
.OnAction = "关闭系统"
End With
End With
.Visible = True
End With
End Sub |
|