不需要VSTO,VBA也能添加按钮到工具栏

电脑技术 电脑技术 1095 人阅读 | 0 人回复 | 2022-05-13

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
看下面的代码
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
        Position:=msoBarFloating, Temporary:=True)
    If Err.Number <> 0 Then
          ' The toolbar's already there, so we have nothing to do
          Exit Sub
    End If

    On Error GoTo ErrorHandler

    ' Now add a button to the new toolbar
    Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)

    ' And set some of the button's properties

    With oButton

         .DescriptionText = "This is my first button"
          'Tooltip text when mouse if placed over button

         .Caption = "DCP Bullet Format"
         'Text if Text in Icon is chosen

         .OnAction = "dcp_bullets"
          'Runs the Sub Button1() code when clicked

         .Style = msoButtonIconAndCaption
          ' Button displays as icon, not text or both

         .FaceId = 12
          ' chooses icon #52 from the available Office icons

    End With
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则