酷!學園

技術討論區 => 程式討論版 => 主題作者是: 小徒兒 於 2008-06-11 16:12

主題: [分享]Excel 建立功能表項目 和工具列按鍵 Commandbar menu
作者: 小徒兒2008-06-11 16:12
Public cmdNewBar As CommandBar
Public WithEvents ctlBtn As CommandBarButton
Public WithEvents ctlBtn2 As CommandBarButton


Private Sub ctlBtn_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)

' Worksheets("Sheet1").Range("A2").Value = 3.14159

'Worksheets("¤W¥«").Range("A2").Value = 3.14159

If Ctrl.Caption = "Colorize Issues And Actions" Then
ColorizeIssuesAndActions
End If

If Ctrl.Caption = "Set Issue Status Colours" Then
SetStatusColours
End If



End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
 On Error Resume Next

Application.CommandBars("ColorizeIssue").Delete


End Sub

Private Sub Workbook_Open()

 On Error Resume Next

Application.CommandBars("ColorizeIssue").Delete

Set cmdNewBar = Application.CommandBars.Add

cmdNewBar.Name = "ColorizeIssue"
With cmdNewBar

        Set ctlBtn = .Controls.Add(msoControlButton)
       
            With ctlBtn
            .Style = msoButtonIconAndCaption
            .BeginGroup = True
            .Caption = "Colorize Issues And Actions"
            .TooltipText = "Colorize Issues And Actions"
            .FaceId = 59
            .Tag = "MyCustomTag"
            End With

        Set ctlBtn2 = .Controls.Add(msoControlButton)
       
            With ctlBtn2
            .Style = msoButtonIconAndCaption
            .BeginGroup = True
            .Caption = "Set Issue Status Colours"
            .TooltipText = "Set Issue Status Colours"
            .FaceId = 629
            .Tag = "MyCustomTag"
            End With


 .Protection = msoBarNoCustomize
 .Position = msoBarTop
 .Visible = True

  End With




'ColorizeIssuesAndActions
'SetStatusColours

End Sub