Sub AddCommandBar() '命令 Dim cbar As CommandBarButton Set cbar = CommandBars("Standard").Controls("临时按钮") IfNot cbar IsNothingThen ExitSub EndIf With CommandBars("Standard") .Protection = msoBarNoProtection With .Controls.Add(msoControlButton, Before:=3) .DescriptionText ="QuitWithoutSave" .Caption ="临时按钮" .TooltipText ="临时按钮" .Style = msoButtonIconAndCaption .OnAction ="QuitWithoutSave" EndWith EndWith End Sub PrivateSub QuitWithoutSave() MsgBox"激活事件:临时按钮" End Sub
2、删除命令按钮
CommandBars("Standard").Controls("临时按钮").Delete
3 修改word命令
'修改word命令 Sub FileSave() MsgBox ActiveDocument.Name If ActiveDocument.Saved =FalseThen ActiveDocument.Save EndIf End Sub Sub FileSaveAs() MsgBox"您不能另存文档" End Sub