作者 主題: [分享]Excel 建立功能表項目 和工具列按鍵 Commandbar menu  (閱讀 5505 次)

0 會員 與 1 訪客 正在閱讀本文。

小徒兒

  • 鑽研的研究生
  • *****
  • 文章數: 622
    • 檢視個人資料
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