请参:例子为在文本快捷菜单的最后位置添加一个名字适于窗口的命令, 当然你可以指定其它的命令(如自定义的,可通过ONACTION方法,第二个例子) Private Sub Document_Close()
On Error Resume Next
Application.CommandBars("text").Reset'恢复
End Sub
Private Sub Document_Open()
On Error Resume Next
Dim NewButton As CommandBarButton
Set NewButton = Application.CommandBars("text").Controls.Add(msoControlButton, ID:=6)
NewButton.Visible = True
End Sub
又见: Private Sub Document_Close() On Error Resume Next Application.CommandBars("text").Controls("MyName").Delete'删除 End Sub Private Sub Document_Open() Dim NewButton As CommandBarButton Call ErrReset On Error Resume Next Set NewButton = Application.CommandBars("text").Controls.Add(Type:=msoControlButton) With NewButton .Caption = "MyName" .OnAction = "MySub" .FaceId = 100 .Visible = True End With End Sub Sub ResetControls()'恢复 Application.CommandBars("text").Reset End Sub |