在word中如何清理右键多余的菜单,
可以写VB脚本来处理。
其中 CommandBars(“Text”) 就是获取了 右键菜单。
这是一个如何添加和如何删除按钮的示例
Public Sub AutoExec()
Dim cb As CommandBar
Dim ctl As CommandBarButton
On Error GoTo bye
CustomizationContext = NormalTemplate
Set cb = CommandBars("Text")
Set ctl = cb.FindControl(Tag:="lower Case")
If ctl Is Nothing Then
Set ctl = cb.Controls.Add(Type:=msoControlButton, _
Before:=9, Temporary:=True)
With ctl
.Caption = "lower Case"
.Tag = "lower Case"
.FaceId = 947
.OnAction = "lowerCase"
End With
Else
cb.Controls("lower Case").Delete
End If
bye:
End Sub
但是实际中,由于对各种空间对象了解不多,所以发现如果要删除对象,最好是获取到对象的ID。
下面就是通过获取对象id后,然后删除掉多余的菜单
Public Sub AutoExec()
Dim cb As CommandBar
Dim ctl As CommandBarButton
On Error GoTo bye
CustomizationContext = NormalTemplate
Set cb = CommandBars("Text")
For Each cmd In cb.Controls
Debug.Print cmd.Caption; cmd.ID
Next
'cb.FindControl(ID:=1).Delete
bye:
End Sub