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、刪除命令按鈕'命令
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
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
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