VBA命令按鈕操作

weixin_30588675發表於2020-04-05
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

轉載於:https://www.cnblogs.com/top5/archive/2009/10/15/1583817.html

相關文章