VBA命令按钮操作

1、添加一个命令按钮
Sub AddCommandBar()
'命令
Dim cbar  As CommandBarButton


Set cbar = CommandBars("Standard").Controls("临时按钮")

If Not cbar Is Nothing Then
    
Exit Sub
End If

    
With CommandBars("Standard")
        .Protection 
= msoBarNoProtection
        
        
With .Controls.Add(msoControlButton, Before:=3)
            .DescriptionText 
= "QuitWithoutSave"
            .Caption 
= "临时按钮"
            .TooltipText 
= "临时按钮"
            .Style 
= msoButtonIconAndCaption
            .OnAction 
= "QuitWithoutSave"
        
End With
    
    
End With
End Sub

Private Sub QuitWithoutSave()
    
MsgBox "激活事件:临时按钮"
End Sub
2、删除命令按钮
CommandBars("Standard").Controls("临时按钮").Delete

3   修改word命令

 

 

'修改word命令
Sub FileSave()

MsgBox ActiveDocument.Name

If ActiveDocument.Saved = False Then
    ActiveDocument.Save
End If

End Sub


Sub FileSaveAs()
    
MsgBox "您不能另存文档"
End Sub

 4、删除顶端菜单

 CommandBars.ActiveMenuBar.Controls("Custom").Delete
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值