今天在解决一个问题的时候,使出了很久不用的VBA。这是在Excel里面的一个特殊功能。

下面是代码的一部分,主要是增加和删除快捷菜单

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'删除工具条
On Error Resume Next
    Dim bar As CommandBar
    Set bar = Application.CommandBars("CELL")
    Dim ctrl As CommandBarControl
    bar.FindControl(Tag:=12000).Delete
End Sub

Private Sub Workbook_Open()
'添加工具条
    Dim bar As CommandBar
    Set bar = Application.CommandBars("CELL")
    Dim ctrl As CommandBarControl
    
    
    '先判断是否有这个工具条
    Dim button  As CommandBarControl
    Set button = bar.Controls.Add(Type:=msoControlButton, temporary:=True)
    With button
        .Caption = "打印标识卡"
        .OnAction = "PrintAction"
        .Tag = 12000
    End With
End Sub


其他与业务有关的代码这里就不贴出来了

相关文章:

  • 2021-09-02
  • 2021-09-22
  • 2022-12-23
  • 2021-05-09
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
猜你喜欢
  • 2021-10-06
  • 2022-12-23
  • 2021-12-15
  • 2021-04-25
  • 2021-12-20
  • 2021-08-24
  • 2021-12-14
相关资源
相似解决方案